4

How to create a list item inside a folders of custom sharepoint list using JSOM ?

Below code is not working http://www.sharepointcolumn.com/create-list-item-in-folders-using-client-object-model/

 

1 Answer 1

6

You can use the SP.ListItemCreationInformation.set_folderUrl method (MSDN).

And here is a simple example:

var clientContext = SP.ClientContext.get_current();
var list = clientContext.get_web().get_lists().getByTitle('Custom');

var itemCreateInfo = new SP.ListItemCreationInformation();
// need to specify full path after site domain , ex: 
// "/sites/DMS/Lists/Custom/Folder" 
itemCreateInfo.set_folderUrl('/sites/DMS/Lists/Custom/Folder');

var listItem = list.addItem(itemCreateInfo);
listItem.set_item('Title', 'Hello!');
listItem.update();

clientContext.load(listItem);
clientContext.executeQueryAsync(function (sender, arges) {
    alert('Added');
}, function (sender, arges) {
    alert(arges.get_message());
});

This will create a new list item under "Folder" in "Custom" list.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.