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?

4
  • What permissions does your app have? Commented Nov 17, 2016 at 15:21
  • Hi wjervis, within AppManifest the Site Collection and Web have Full Control. User Profiles (Social) has Read access? Commented Nov 18, 2016 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. Commented Nov 18, 2016 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... Commented Nov 18, 2016 at 14:47

1 Answer 1

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); } } 
1
  • 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. Commented Nov 17, 2016 at 10:38

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.