Could somebody give a JavaScript CSOM example of how to move/copy a document set from one document library to another? The document set has a derived content type with a list of metadata, and it contains files in subfolders.

1 Answer 1


You can use below snippet to get the document set

Check if a document set exists

function getDocSet(listTitle,docSetName, success,error) {
var context = SP.ClientContext.get_current();
var list = context.get_web().get_lists().getByTitle(listTitle);
var items = list.getItems(createGetDocSetQuery(docSetName));
  function() {
     var docSetItem = (items.get_count() > 0 ? items.getItemAtIndex(0) : null);

function createGetDocSetQuery(docSetName)
    var query = new SP.CamlQuery();
    var viewXml =
    "<View>" +
    "<Query>" +
       "<Where>" +
           "<And>" +
               "<Eq>" +
                  "<FieldRef Name=\"FSObjType\"/>" +
                  "<Value Type=\"Integer\">1</Value>" +
               "</Eq>" +
               "<Eq>" +
                  "<FieldRef Name=\"FileLeafRef\" />" +
                  "<Value Type=\"Text\">" + docSetName + "</Value>" +
               "</Eq>" +
           "</And>" +
       "</Where>" +
    "</Query>" +
    "<RowLimit>1</RowLimit>" +
    return query;

Once you have that, you can create/move using

Create a document set with JSOM

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);

var parentFolder = list.get_rootFolder();

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

ctx.executeQueryAsync(function (){ 
    SP.DocumentSet.DocumentSet.create(ctx, parentFolder, docSetName, docSetContentType.get_id());
  • Thank you very much. This gives me some idea of how to handle document sets by CSOM JavaScript. The crucial point, however, is the move operation, which is not clear to me from your example. The move operation is to be called through a ribbon button. The user selects a list of document set items in a document library, then hits a ribbon button to move the selected list of document sets from this library to another library. Dec 16, 2014 at 20:27
  • As part of creating the ribbon custom action you can get the selected item.. Move is same as Create..after creating you can just delete the old one. Dec 16, 2014 at 20:31
  • 1
    But creating a new document set is not the same as moving a document set. The newly created one will necessarily have a diffenent ID (thus no be the same document set). And what about the contents of the document set (files, subfolders)? Dec 16, 2014 at 22:08
  • 1
    In my understanding, moving a document set means to move THE SAME document set from one position to another, with the same unique ID and with all its contents. Dec 16, 2014 at 22:10

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.