I'm trying to determine whether a document set exists - if it doesn't I'll send it off to another function to create but I'm not getting the correct value back from my query.
I think it has to do with the document set behaving more like a folder than a list but I'm unsure how I'd go about a similar query to a folder.
function checkIfDocSetExists() {
var docSetExists = false;
var listItems;
function checkForDocSet() {
var clientContext = new SP.ClientContext();
var targetList = clientContext.get_web().get_lists().getByTitle('Source Files');
var query = new SP.CamlQuery();
query.set_viewXml("<View><Query><Where><Contains><FieldRef Name='Title'/><Value Type='Text'>" + thisItemID + "</Value></Contains></Where></Query></View>");
listItems = targetList.getItems(query);
clientContext.load(listItems);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded() {
var listEnumerator = listItems.getEnumerator();
while (listEnumerator.moveNext()) {
console.log("Item found! \nTitle: " + listEnumerator.get_current().get_item("Title"));
}
docSetExists = true;
}
function onQueryFailed(sender, args) {
console.log('Request failed. \nError: ' + args.get_message() + '\nStackTrace: ' + args.get_stackTrace());
docSetExists = false;
}
checkForDocSet();
(docSetExists == false) ? CreateDocumentSet() : false;
}