0

Instead of clicking on the Library > New Document > Document Set Name, is there a way that I can bypass all of that from a command button on a Site Page? I have tried creating Shortcut to the Create new document dropdown link, but when doing that, it recreates the GUID (disallowing it to be unique), which creates an error.

I put this into script editor and it didn't work, but can;t figure out why: referenced: sp.runtime.js, jquery-1.7.1.min.js, sp.js, and SP.DocumentManagement.js

Then, the entire script I used -- I excluded app.js. What am I doing wrong?

    <div>
    <p id="text" style="font-size: medium">
    Enter a Name for the Analysis Document Set</p></div>
    <div>
    <input type="text" id="txtGetDocumentSetName" name="DocumentSetName" />
    <input type="button" id="btnCreateDocumentSet" name="bCreateDocumentSet"                                 value="Create Document Set" onclick="javascript: CreateDocumentSet()" /> 
    </div>

    <script type="text/javascript">
    function CreateDocumentSet() {

    var ctx = new SP.ClientContext(SPHostUrl); 
    var parentFolder; 
    var newDocSetName = $('#txtGetDocumentSetName').val(); 
    var docSetContentTypeID = "0x0120D520";

    var web = ctx.get_web(); 
    var list = web.get_lists().getByTitle('Research Document Set'); 
    ctx.load(list);

    parentFolder = list.get_rootFolder(); 
    ctx.load(parentFolder);

    var docsetContentType =         web.get_contentTypes().getById(docSetContentTypeID); 
    ctx.load(docsetContentType);

    ctx.executeQueryAsync(function () { 
    var isCreated = SP.DocumentSet.DocumentSet.create(ctx, parentFolder,          newDocSetName, docsetContentType.get_id()); 
    ctx.executeQueryAsync(SuccessHandler('Document Set creation         successful'), FailureHandler("Document Set creation failed")); 
    }, FailureHandler("Folder loading failed"));


    ctx.add_requestSucceeded(function () { 
    $('#txtGetDocumentSetName').val(''); 
    alert('Request Succeeded'); 
    });

    ctx.add_requestFailed(function (sender, args) { 
    alert('Request failed: ' + args.get_message()); 
    }); 
    }

    // Failure Message Handler

    function FailureHandler(message) { 
       return function (sender, args) { 
            alert(message + ": " + args.get_message()); 
        } 
    }



    // Success Message Handler

    function SuccessHandler(message) { 
        return function () { 
            alert(message); 
        } 
    }
0

i would insert a script webpart to the page and add a script like the following:

function createDocumentSet(siteUrl,listTitle,docSetName,success,error) {
    var ctx = new SP.ClientContext(siteUrl);
    var web = ctx.get_web();
    var list = web.get_lists().getByTitle(listTitle);
    ctx.load(list);

    var parentFolder = list.get_rootFolder();
    ctx.load(parentFolder);

    var docSetContentTypeID = "0x0120D520";
    var docSetContentType = ctx.get_site().get_rootWeb().get_contentTypes().getById(docSetContentTypeID);
    ctx.load(docSetContentType);

    ctx.executeQueryAsync(function (){ 
        SP.DocumentSet.DocumentSet.create(ctx, parentFolder, docSetName, docSetContentType.get_id());
        ctx.executeQueryAsync(success,error);
    }, 
    error);
}

and then use is like this (i would add an HTML Button as you wanted and put this function onClick):

SP.SOD.executeFunc('sp.documentmanagement.js', 'SP.DocumentSet.DocumentSet', function() {

   createDocumentSet(_spPageContextInfo.webAbsoluteUrl,'Documents','Orders',printInfo,logError);

   function printInfo()
   {
      console.log('Doc Set has been created');  
   }

   function logError(sender,args)
   { 
      console.log(args.get_message());
   }

});

Reference to SE question Create a document set with JSOM

  • Figured most of that out...still stuck on what 'Document' and 'Orders' is referring to. Please help if you get a sec? – TheJDScott Oct 14 '15 at 14:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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