0

Good afternoon,

Has anyone experienced an issue within the last couple of days regarding using JSOM to create Document Sets within the SharePoint add-in web? I am working on a project where we had code running to create document sets on the fly which worked OK. There is now an "unknown" error appearing, with no changes to the code. Thanks in advance.

Update, use:

var docsetContentType = list.get_contentTypes().getById(docSetContentTypeID);

instead of:

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

And use the full content type ID for the document set.

Only issue now, is that the Server Relative URL is now Forbidden 403, where it wasn't before? Anyone else seen this behaviour after fixing their doc set automation code?

  • What permissions does your app have? – wjervis Nov 17 '16 at 15:21
  • Hi wjervis, within AppManifest the Site Collection and Web have Full Control. User Profiles (Social) has Read access? – alr84 Nov 18 '16 at 8:18
  • Those are sufficient permissions (the full control on web is redundant if the site collection has it though), so not sure why you would be getting that error. I'd double check url's, make sure they are all valid. – wjervis Nov 18 '16 at 12:05
  • Yep, all URLs are valid, and are being accessed from within the SharePoint UI once the document set has been created. Weird how it was accessible before. Even the links within the menu popup no longer work... – alr84 Nov 18 '16 at 14:47
0

Not sure whats changed but i got the doc set created using below code

function CreateDocumentSet() {

var ctx = new SP.ClientContext(sitename);
var parentFolder;
var newDocSetName = "A";
var docSetContentTypeID = "0x0120D520";

var web = ctx.get_web();
var list = web.get_lists().getByTitle('Documents');
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 () {
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);
    }
}
  • Hi Monica, thanks for sharing. Your code is very similar to what I had working before the start of this week, then it stopped working. The changes I made seemed to fix the issue, not sure what happened to break it though, as the code was untouched. Anyway - I now have 403 Forbidden when I try access the newly created document sets - I am running SharePoint Online - with a SharePoint hosted add-in. The server relative URL of the document set worked OK before the change. – alr84 Nov 17 '16 at 10:38

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.