How to get SharePoint List Version using JSOM in SharePoint Online?

    var Ctx = new SP.ClientContext.get_current();
    if (Ctx) {
        var Web = Ctx.get_web();
        var List = Web.get_lists().getByTitle(Name);                
        var query = new SP.CamlQuery();
        query.set_viewXml(xmlQuery);
        var listItems = List.getItems(query);
        Ctx.load(listItems);				
        Ctx.executeQueryAsync(function (sender, args) {
            that.DataSet = [];
            var objlistEnumerator = objlistItems.getEnumerator();
            while (objlistEnumerator.moveNext()) {
                var objListItem = objlistEnumerator.get_current();
                var id = objListItem.get_item('ID');
                var filePath = 'https://mysharepoint/Lists/Preservenature/'+id+'_.000'
                var web = objClientCtx.get_web();
                var listItemInfo = web.getFileByServerRelativeUrl(filePath)
                var listItemFields = listItemInfo.get_listItemAllFields()
               Ctx.load(web);
                Ctx.load(listItemInfo);
               Ctx.load(listItemFields);
               
                Ctx.executeQueryAsync(
				    function (sender, args) {
					    var fileVersions = listItemInfo.get_versions();
					    Ctx.load(fileVersions);
					    Ctx.executeQueryAsync(
						    function (sender, args) {
							    var objlistVersionEnumerator = fileVersions.getEnumerator();
							    while (objlistVersionEnumerator.moveNext()) {
								    var objCurrentListItemVersion = objlistVersionEnumerator.get_current();
								    console.log(objCurrentListItemVersion.get_url());
							    }
			
						    },
						   
    }
}

Happy SharePointing.!!!

Leave a Reply

Your email address will not be published.