I need to display all version using jslink or javascript in custom list. Is it possible to get version history for item in custom list?
1 Answer
According to your post, my understanding is that you want to get list item version using JavaScript Client Object Model.
The following code snippet for your reference:
that.getData = function (listName, xmlQuery, contentType, onGetSuccess) {
var objClientCtx = new SP.ClientContext.get_current();
if (objClientCtx) {
var oWeb = objClientCtx.get_web();
var oList = oWeb.get_lists().getByTitle(listName);
var query = new SP.CamlQuery();
query.set_viewXml(xmlQuery);
var objlistItems = oList.getItems(query);
objClientCtx.load(objlistItems);
objClientCtx.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 = 'your site collection/Lists/your list/'+id+'_.000'
var web = objClientCtx.get_web();
var listItemInfo = web.getFileByServerRelativeUrl(filePath)
var listItemFields = listItemInfo.get_listItemAllFields()
objClientCtx.load(web);
objClientCtx.load(listItemInfo);
objClientCtx.load(listItemFields);
//objClientCtx.load(versions1);
objClientCtx.executeQueryAsync(
function (sender, args) {
var fileVersions = listItemInfo.get_versions();
objClientCtx.load(fileVersions);
objClientCtx.executeQueryAsync(
function (sender, args) {
var objlistVersionEnumerator = fileVersions.getEnumerator();
while (objlistVersionEnumerator.moveNext()) {
var objCurrentListItemVersion = objlistVersionEnumerator.get_current();
console.log(objCurrentListItemVersion.get_url());
}
},
function (sender, args) {console.log('Error');}
)
},
function (sender, args){
console.log('error')
});
}
onGetSuccess(that.DataSet);
}, function (sender, args) {
that._onGetFail(sender, args);
});
}
}
More information is here: How to get all versions of a SharePoint list using JSOM
-
-
Can it be possible using jslink?Akshay– Akshay2017-10-13 04:47:48 +00:00Commented Oct 13, 2017 at 4:47
-
JsLink is only applicable to Views,Content Types,columns and Items not specific to item's version. You can create the list view that only for viewing the items in version wise and then apply the jslink to that view.san– san2017-10-13 04:53:21 +00:00Commented Oct 13, 2017 at 4:53
-
Is it possible to get version history for lookup column in custom list using above jquery refrence?Akshay– Akshay2017-10-13 05:46:28 +00:00Commented Oct 13, 2017 at 5:46
