1

I am trying to add a folder to the document set but the folder got created at the parent document library. Can somebody help me to find out what am i doing wrong ?

Following is the code:

var createFolder = function(context, list, foldername) {
        var itemCreateInfo = new SP.ListItemCreationInformation();
        itemCreateInfo.set_underlyingObjectType(SP.FileSystemObjectType.folder);
        itemCreateInfo.set_leafName(foldername);
        itemCreateInfo.set_folderUrl = String.format("/Lists/{0}/{1}", "Documents", "Custom");
        var listItem = list.addItem(itemCreateInfo);
        listItem.set_item('Title', foldername);
        listItem.update();
        context.load(listItem);
        context.load(list);
        context.executeQueryAsync(
            Function.createDelegate(this, successHandler()),
            Function.createDelegate(this, errorHandler));

        function successHandler() { console.log('Success'); }

        function errorHandler() { alert("Request failed: message = " + arguments[1].get_message()); }
    }

"Documents" is the document library and "Custom" is the document set in above code.

Thanks.

4
  • your error probably is in the context.load. Remove context.load(list); and try again. And the set_folfer_url property is not necesary.
    – Marco
    Commented Jun 9, 2016 at 18:37
  • 2
    I don't think your URL should have /Lists in it, since document sets are in a library, not a list.
    – Erin L
    Commented Jun 9, 2016 at 18:49
  • @ErinL it works, Thanks. /Lists was actually the problem.
    – Maddy
    Commented Jun 9, 2016 at 19:11
  • @Maddy, then please mark Erins answer below as the good one, everyone gets points and future searches will be better Commented Jun 10, 2016 at 9:43

1 Answer 1

3

Your URL shouldn't have /Lists in it, since document sets are in a library, not a list.

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.