Using the following JavaScript function, I am able to get all versions of a specified list item:
function getListItemVersions(listTitleOrId, listItemId) {
let context = null;
let web = null;
try {
context = SP.ClientContext.get_current();
web = context.get_web();
let filePath = `/Lists/${listTitleOrId}/${listItemId}_.000`;
let listItemInfo = web.getFileByServerRelativeUrl(filePath);
let listItemFields = listItemInfo.get_listItemAllFields();
context.load(web);
context.load(listItemInfo);
context.load(listItemFields);
context.executeQueryAsync(
function (sender, args) {
let fileVersions = listItemInfo.get_versions();
context.load(fileVersions);
context.executeQueryAsync(
function (sender, args) {
let objlistVersionEnumerator = fileVersions.getEnumerator();
while (objlistVersionEnumerator.moveNext()) {
let objCurrentListItemVersion =
objlistVersionEnumerator.get_current();
console.log(objCurrentListItemVersion);
}
},
function (sender, args) {
console.log('Error getting versions from server', sender, args);
}
)
},
function (sender, args) {
console.log('Error getting list from server', sender, args);
}
);
} catch(e) {
}
}
For example, if I have a list called "Test List" which has an item with an ID of 23, I can call getListItemVersions("Test List", 23) and have all versions of the item logged. The problem is that I'm getting back objects of the type SP.FileVersion, i.e.:
Using the SP.FileVersion returned, how can I get the values of the fields at each version of the list item?
