1) Batch Add Items to List:
2) Batch Update Items from List:
3) Batch Delete Items from List:
Now let us analyze what happens behind the scenes when we make one of these batch operations. Here is the firebug screen grab of the call to batch create 5 items:Now as you can see, only one call is made from the client to the server. It contains all the XML necessary for creating the 5 items. Here is the relevant XML:
Hope you enjoyed this blog post. Happy SharePointing!
Addendum: I would also like to point out one of the hidden gems of the SharePoint world: if you are using Server Side Code (Full Trust), there is a similar batch method available called SPWeb.ProcessBatchData which can be used to bulk add, edit and delete list items. This is really helpful because it can operate on large number of items at once without making repeated calls to the database.
16 comments:
Good one ...Liked it... REST API is very powerful. And at least you have not used spservices to do the same.
Awsome post. Like the idea of optimizing calls for server from client infrastructure to perform batch operation.
NIce and useful article
If you have multiple columns, should they all be on the same row within the oListItem.set_Item() line or separate oListItem.set_Item lines?
I would go for multiple oListItem.set_Item lines.
Hello,
Can we do this using C# (using Microsoft.SharePoint.dll) ?
Hello
Can we do this using C#(Client object model)?
Thank you Vardhaman. Small doubt.
What if you dont have ID's and If you have to iterate ListItemCollection that you got from a CAML Query to update?
So far to iterate such collection, i have used async's success method. But now, after i get the collection and in iteration, i have to update each item. In this case, do i need to call one more async's success method??
please clarify my doubt.
ItemArray is not required in say, creating list items... clientContext.load(oListItem); should be sufficient since you are loading it in loop..it works without the array. Or may be you have used it for a specific reason which I have not understood ? :)
is there a way to track this batch process? e.g. if I send 50 items batch to delete those items, server takes its own time to delete these 50 items and only then we get to know that its done.
I would really like to have counter shown in console.log, when it deletes item, so that end user wont live status.
I tried stupid solution of adding, console.log inside for Loop, but figured out its Async call. Might not be possible at all unless there is inbuilt method to track.
But your insights will be great, oe how you would do it? :).. thank you!
Thanks for the great article, can we do the same for getItems(camlQuery) from different lists? And in OnSuccess() how to handle different listItemCollections?
Something like below,
for (var i = 0; i < listCollection.length; i++) {
var list = list + i;
list = hostContext.get_web().get_lists().getByTitle(listCollection[i]);
listItems = list.getItems(camlQuery);
clientContext.load(listItems);//not sure how this will work
}
clientContext.executeQueryAsync(onQuerySucceeded, onQueryFailed);
Any recommendations on how to retrieve all document libraries from multiple sites within the same collection?
@Kessy,
Could you not do it using search?
What is the maximum size of the request that is allowed for batch operations?
How to check if data exist in list before inserting bulk data
Hi , can you please help, how to save date from datepicker in SharePoint list, date is getting saved but one day earlier.
Post a Comment