Forum Discussion
SharePoint Online JavaScript creates folder instead of document set
Hello! We have a SharePoint Online system with 4 custom new forms created with Html/JavaScript. These forms used to create document sets and worked very well for a year (the forms are for different document libraries on different subsites). Starting yesterday, they suddenly creating folders instead of document sets.
Interesting, but the folders have the correct content type, not Folder content type. We checked and the content type id's havent changed. Here is the JS code:
function createDocset() {
var ctx = new SP.ClientContext(_spPageContextInfo.webServerRelativeUrl);
var web = ctx.get_web();
var list = web.get_lists().getByTitle('dummy');
SP.SOD.executeFunc('sp.js', 'SP.ClientContext');
newDocSetName = 'dummy';
var docSetContentTypeID = '0x0120D52000A5EFC11713588E41B8E1058A74F53AF2';
currentDate = new Date().getFullYear();
ctx.load(list);
folderUrl = "dummy" + currentDate;
var folder = web.getFolderByServerRelativeUrl(folderUrl);
ctx.load(folder);
var docsetContentType = web.get_contentTypes().getById(docSetContentTypeID);
ctx.load(docsetContentType);
ctx.executeQueryAsync(function () {
console.log("Content-type: " + docsetContentType);
isCreated = SP.DocumentSet.DocumentSet.create(ctx, folder, newDocSetName, docsetContentType.get_id());
console.log("Created: ", isCreated);
ctx.executeQueryAsync(SuccessHandler('Document Set creation successful'), FailureHandler("Document Set creation failed"));
}, FailureHandler("Folder loading failed"));
ctx.add_requestSucceeded(function () {
});
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 () {
setDocset();
}
}}
There are 2 custom document set content types in this library. The forms using their content type id's. The id's havent changed.
Thank you very much!
This issue seems to be due to some changes in SharePoint Online after 12th January.
To fix this issue: use the list.contentTypeID instead of web.ContentTypeID.
Change your code like this:
var docSetContentTypeID = '<The list DocumentSet contentTypeID>'; currentDate = new Date().getFullYear(); ctx.load(list); folderUrl = "dummy" + currentDate; var folder = web.getFolderByServerRelativeUrl(folderUrl); ctx.load(folder); //use list.get_contentTypes() var docsetContentType = list.get_contentTypes().getById(docSetContentTypeID); ctx.load(docsetContentType);Check more information in below related threads:
- SharePoint Online JavaScript creates folder instead of document set
- Document Set created programmatically not working anymore since 12 Jan 2021
Please click Mark as Best Response if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
4 Replies
This issue seems to be due to some changes in SharePoint Online after 12th January.
To fix this issue: use the list.contentTypeID instead of web.ContentTypeID.
Change your code like this:
var docSetContentTypeID = '<The list DocumentSet contentTypeID>'; currentDate = new Date().getFullYear(); ctx.load(list); folderUrl = "dummy" + currentDate; var folder = web.getFolderByServerRelativeUrl(folderUrl); ctx.load(folder); //use list.get_contentTypes() var docsetContentType = list.get_contentTypes().getById(docSetContentTypeID); ctx.load(docsetContentType);Check more information in below related threads:
- SharePoint Online JavaScript creates folder instead of document set
- Document Set created programmatically not working anymore since 12 Jan 2021
Please click Mark as Best Response if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
- spdev2013Copper ContributorIt worked. Thankyou
- spdev2013Copper Contributor
We are also getting affected by this patch update from Microsoft. looking for a solution from Microsoft.
- warrenbartonCopper Contributor
Greetings! You can find a workaround here: https://sharepoint.stackexchange.com/questions/288764/sharepoint-online-javascript-creates-folder-instead-of-document-set