Skip to content

Instantly share code, notes, and snippets.

@simkessy
Last active August 9, 2017 00:10
Show Gist options
  • Save simkessy/a3f7533cf795f2babadfc2285fdbc286 to your computer and use it in GitHub Desktop.
Save simkessy/a3f7533cf795f2babadfc2285fdbc286 to your computer and use it in GitHub Desktop.
Get files in document set
// Get working group files
getFiles: function(id) {
var d = $.Deferred();
var opts = {
listName: "WgDocuments",
CAMLQuery: "<Query><OrderBy><FieldRef Name='Created' Ascending='False'/></OrderBy><Where><And><Eq><FieldRef Name='FSObjType' /><Value Type='Integer'>0</Value></Eq><IsNotNull><FieldRef Name='ID' /></IsNotNull></And></Where></Query>",
CAMLQueryOptions: "<QueryOptions><ViewAttributes Scope='RecursiveAll' /></QueryOptions>",
CAMLRowLimit: 5
}
// Give me files for 1 WG if ID given, otherwise give all files
/*
<Query>
<OrderBy>
<FieldRef Name='Created' Ascending='False' />
</OrderBy>
<Where>
<And>
<Eq>
<FieldRef Name='FSObjType' />
<Value Type='Integer'>0</Value>
</Eq>
<Eq>
<FieldRef Name='wgID' />
<Value Type='Text'>" + id + "</Value>
</Eq>
</And>
</Where>
</Query>
*/
if (!_.isUndefined(id)) {
opts.CAMLQuery = "<Query><OrderBy><FieldRef Name='Created' Ascending='False'/></OrderBy><Where><And><Eq><FieldRef Name='FSObjType' /><Value Type='Integer'>0</Value></Eq><Eq><FieldRef Name='wgID'/><Value Type='Text'>" + id + "</Value></Eq></And></Where></Query>"
opts.CAMLRowLimit = 0
}
var promise = $().SPServices.SPGetListItemsJson(opts);
promise.then(function() {
var files = this.data
files.map(function(file, i) {
files[i].filename = file.FileRef.lookupValue.split("/").slice(-1)[0];
files[i].modified = moment(file.Modified).format(wg.dateFormat);
files[i].Created = moment(file.Created_x0020_Date.lookupValue).format(wg.dateFormat);
files[i].creator = file.Editor.userName.split("(")[0];
files[i].path = "/" + file.FileRef.lookupValue;
})
d.resolve(files);
// console.log(files)
});
return d.promise();
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment