-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathgetVersions.js
More file actions
29 lines (25 loc) · 991 Bytes
/
getVersions.js
File metadata and controls
29 lines (25 loc) · 991 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import ajax from '../utils/ajax.js'
/**
@name $SP().list.getVersions
@function
@description When versionning is activated on a list, you can use this function to get the different versions of a list item
@param {Number} ID The item ID
@return {Promise} resolve(arrayOfVersions)
@example
$SP().list("My List").getVersions(1234).then(function(versions) {
versions.forEach(function(version) {
console.log(version);
})
});
*/
export default async function getVersions(itemID) {
if (!this.listID) throw "[SharepointPlus 'getVersions'] the list ID/Name is required.";
if (!this.url) throw "[SharepointPlus 'getVersions'] not able to find the URL!"; // we cannot determine the url
if (!itemID) throw "[SharepointPlus 'getVersions'] the item ID is required.";
return ajax.call(this, {
url:this.url + "/_api/lists/getbytitle('"+this.listID+"')/Items("+itemID+")/Versions"
})
.then(res => {
return ((res.d ? res.d.results : res.value)||[])
})
}