I'm trying to generate document sets on the fly with the following code. It is using /_layouts/15/SP.DocumentManagement.js for the SP.DocumentSet.DocumentSet.create method which takes four parameters.
The last parameter is supposed to be a content type id object but I'm getting an exception in the console that I haven't been able to unravel. Uncaught Error: Object reference not set to an instance of an object on server. The object is associated with method GetById.
I'm following these guidelines for creating it. Can anyone point me in the right direction for this error?
function CreateDocumentSet() {
var ctx = new SP.ClientContext(siteUrl);
var parentFolder;
var docSetContentTypeID = "0x0120D520008C04C8264B92224699E49B9BE493F460";
var web = ctx.get_web();
var list = web.get_lists().getByTitle('Source Files');
ctx.load(list);
parentFolder = list.get_rootFolder();
ctx.load(parentFolder);
var docsetContentType = web.get_contentTypes().getById(docSetContentTypeID);
ctx.load(docsetContentType);
ctx.executeQueryAsync(function () {
SP.DocumentSet.DocumentSet.create(ctx, parentFolder, thisItemID, docsetContentType.get_id());
ctx.executeQueryAsync(
SuccessHandler('Document Set creation successful'),
FailureHandler("Document Set creation failed")
);
}, FailureHandler("Folder loading failed"));
}