I am attempting to create a document set in sharepoint online using JSOM triggered by a button. I've found the guides referenced here on the subject, but I can't seem to find the issue in my code.

When trying to execute the query its throwing the error: msajaxbundle.js:1 Uncaught TypeError: Cannot read property 'apply' of undefined

It seems like the Async query is failing, but im not sure why. I have also tried using list level content types and site level types with the appropriate methods for that level.

Lifeline.Functions.createCase = function(){
    context = new SP.ClientContext(_spPageContextInfo.webServerRelativeUrl);
    var listId = '7BC07117AE-8792-43DE-984A-D6EA2A533B6C';
    list = context.get_web().get_lists().getById(listId);
    var docSetName = "Projection Case: Please Work ";
    list = context.get_web().get_lists().getById(listId);

    console.log("list loaded");

    var parentFolder = list.get_rootFolder();
    console.log("parent folder loaded")

    var docSetContentTypeID = "0x0120D520";
    var docSetContentType =  context.get_site().get_rootWeb().get_contentTypes().getById(docSetContentTypeID);
    console.log("doc set content type loaded");
    context.executeQueryAsync( function(){
        console.log("doc set content query executed");

        Sp.DocumentSet.DocumentSet.create(context, parentFolder, docSetName, docSetContentType.get_id());
        context.executeQueryAsync(successHandler(), function logerror(sender,args){
    Function.createDelegate(this, this.onQueryFailed));
function successHandler(){
alert("Document Set successfully Created");
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());

1 Answer 1


So I wasn't able to fix the code to resolve the error. However I was able to get this working using an alternate method that seems much simpler. Hopefully it will help those who are also having difficulty executing this using DocumentSet.DocumentSet.create method

Lifeline.Functions.createCase = function(itemid) {
var docSetName = "my document set name";
var context = new SP.ClientContext(_spPageContextInfo.webServerRelativeUrl);
var list = context.get_web().get_lists().getById('LIST GUID');
var item;

var itemCreateInfo = new SP.ListItemCreationInformation();

item = list.addItem(itemCreateInfo);
item.set_item("ContentTypeId", "0x0120D52000307A54BE1A445A44813BEDE85E22CADB");
item.set_item('Title', docSetName);
item.set_item('DocumentSetDescription', "This is test 3 an automatically generated description");
item.set_item('ChartIdlookup', itemid);

    function() { console.log("document-set created!");} ,
    function(sender,args) { console.log("Error: " + args.get_message()); }


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.