Question

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.

doc library screenshot

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

Thank you very much!

EDIT: There are 2 custom document set content types in this library. The forms using their content type id's. The id's havent changed.

enter image description here

enter image description here

Was it helpful?

Solution

This could be the document set content type is removed from your library, please check if the document set content type is under the content types in library settings.

enter image description here

If it is there, you could try to use the ContentTypeID for document set: var docSetContentTypeID = '0x0120D520';

Update:

I reproduce your issue on my tenant. You could check my answer here: https://docs.microsoft.com/en-us/answers/questions/230335/document-set-created-programmtically-not-working-a.html?childToView=231298#answer-231298

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

To get the list contenttype id, go to library settings, click the document set content type. You could find it in the url.

enter image description here

Use this list contentTypeID would fix this:

enter image description here

OTHER TIPS

Our customer has the same problem. It appears since 4 p.m. 12th January 2021 German time. We did not change anything in the system since ~ 12 months. Here a excerpt of the source code:

var itemCreateInfo = new SP.ListItemCreationInformation();
itemCreateInfo.set_underlyingObjectType(SP.FileSystemObjectType.folder);
itemCreateInfo.set_leafName(title().trim());
var item = list.addItem(itemCreateInfo);

item.set_item('ContentTypeId', '0x....');

item.update();
context.load(item);
context.executeQueryAsync(function(sender, args) {

}, function(sender, args){      
    alert(args.get_message());
}); 

It looks like this:

The document set is created correctly, it is accessable via docsethomepage.aspx In our opinion, the only difference is the icon and the link (to empty folder instead of docsethomepage.aspx) because the other columns are displayed correctly. So, we decided to open a ticket at the Microsoft Support. Additionally, as a temporary fix, we will use CSR (client side rendering) to fix the icon and the link.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top