SharePoint 2013 Create A Document Set Programatically Using JSOM

Document set

To create and manage multi-document work products consistently, we can use document sets. For this, we need to configure a new document set content type for each multi-document work product, which they typically create.

The document set content type is a folder-based content type, which organizes multiple related documents into a single view, where they can work on and managed as a single entity. 

Include JS file given below before we execute the function.

sp.documentmanagement.js

Site Collection administrator is required to activate the document sets feature before you create or configure new document set content types.

Go to the top-level site in the Site Collection for which you want to enable document sets.
  • Site Actions menu-->click Site Settings.
  • Site Collection Administration-->click Site collection features.
  • Find document sets in the list and click Activate.
  • Call the reusable function.
  1. SP.SOD.executeFunc('sp.documentmanagement.js''SP.DocumentSet.DocumentSet'function() {  
  2.   
  3.    createDocumentSet(_spPageContextInfo.webAbsoluteUrl,'TutorialDocuments','Tutorials',printInfo,logError);  
  4.   
  5.    });  
  6. shareimprove this answer  
  7.   
  8.   
  9. function createDocumentSet(Url,listname,docSetName,success,error) {  
  10.     var context = new SP.ClientContext(Url);  
  11.     var web = context.get_web();  
  12.     var list = web.get_lists().getByTitle(listname);  
  13.     context.load(list);  
  14.   
  15.     var parentFolder = list.get_rootFolder();  
  16.     context.load(parentFolder);  
  17.   
  18.     var docSetContentTypeID = "0x0120D520";  
  19.     var docSetContentType = context.get_site().get_rootWeb().get_contentTypes().getById(docSetContentTypeID);  
  20.     context.load(docSetContentType);  
  21.   
  22.     context.executeQueryAsync(function (){   
  23.         SP.DocumentSet.DocumentSet.create(context, parentFolder, docSetName, docSetContentType.get_id());  
  24.         context.executeQueryAsync(success,error);  
  25.     },   
  26.     error);  
  27. }   
Thanks for reading my blog. Please post your feedback, so that I can improve.