1

I am trying to add folders to a library using JSOM. I need to set the content type of the new library items, however I am not finding the documentation on how to do that anywhere.

var itemCreateInfo = new SP.ListItemCreationInformation();
itemCreateInfo.set_underlyingObjectType(SP.FileSystemObjectType.folder);
itemCreateInfo.set_leafName("test3");
var oListItem = empLib.addItem(itemCreateInfo);
oListItem["ContentTypeID"] = "Employee Folder";
oListItem.update();

This is the code that I have used so far, and it just adds an item of content type folder.

I use the 2nd and 3rd lines for 2 reasons:

  1. The content type I need inherits from folder
  2. Without those lines (just adding a standard item to the library), when trying to add items it gave me an error telling me to use SPFileCollections.Add, which does not work.

I would greatly appreciate any insight on the subject.

0

It looks like you're trying to set the ContentTypeId to the name of your content type. A ContentTypeId should look something like 0x012000...

Try finding the content type ID of your content type and setting that.

0

You're not actually retrieving the content type ID, which is required to make the association with the list. Assuming you have already registered the content type with this list, here's how you get the ContentTypeID

var CTID = empLib.get_contentTypes().getByTitle("Employee Folder").get_id()

That can then be added to the list item with

oListItem.set_item('ContentTypeId', CTID);

The rest looks to be on the right track.

Source

https://derekgusoff.wordpress.com/2012/10/09/working-with-content-types-in-the-javascript-client-object-model/

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.