2

I've searched the jQuery SPServices code examples and MSDN references for an simple example how to update several ListItems using a Where-Clause.

Code for updating a single ListItem with ID = 500, looks like this:

$(divId).html(waitMessage).SPServices({
    operation: "UpdateListItems",
    listName: "MyList",
    ID: 500,
    valuepairs: [["MyField", 1]],
    completefunc: function (xData, Status) {
    	$(divId).html("");
    }
});

But is it also possible to add a Where like :

<Where><Eq><FieldRef Name="Status"/><Value Type="Text">Ready</Value></Eq></Where>

Or should I do it like this post ? (First retrieve the list and then do a loop for each item ?)

2

there. If you are using jQuery and the Web Services (hopefully with my SPServices library!), you have to do the two step process. Call GetListItems with your CAMLQuery first to get the items you need to work with and then call UpdateListItems to make the changes.

This isn't my design, by the way, it's just the way the SharePoint Lists Web Service works. When in doubt, always go to the source documentation on MSDN to see what each operation requires for parameters. I have links on all of the operations in SPServices which take you directly to the appropriate page on MSDN.

Finally, the Batch idea in UpdateListItems is a little bit misleading in its terminology. You can, in fact, "batch" requests into one UpdateListItems call, but you may or may not want to do that based on what your error handling requirements are. Again, best to check the SDK on MSDN.

EDIT: I added a new function to SPServices in v0.5.8 called SPUpdateMultipleListItems to do this: http://spservices.codeplex.com/wikipage?title=%24%28%29.SPServices.SPUpdateMultipleListItems

  • Marc D Anderson, SPUpdateMultipleListItems have any limit? When my query returns 100 items, everything runs ok, but when my query return 700+ items I'm getting error and zero items are updated. – Joao Paulo May 23 '18 at 17:33
  • 1
    There’s no specific limit; it’s more constrained based on the payload sizes. You may need to break your updates into chunks. I usually tried to stick to fewer than 100 items, but YMMV. – Marc D Anderson May 23 '18 at 21:54
1

I havent tried doing this specifically on jQuery, but you can for updating multiple list items using a batch update.

You use CAML to create batch commands and execute the command using ProcessBatchData method on SPWeb object.

Theres a good code sample on doing this on MSDN http://msdn.microsoft.com/en-us/library/cc404818.aspx

  • I only want to use clientside jQuery and SPServices, so your solution is good, but not feasible for me. – Stef Heyenrath Feb 22 '10 at 14:11
  • fair enough, you will have to wait until Marc is back from vacation :-) – Anders Rask Feb 22 '10 at 21:52
1

His library does support a batch update, but I am not yet sure if the batch update supports a CAML query. If you are going to update multiple items, you could use the GetItems service with a CAML query to retrieve the items you want to update. You could then use the jQuery each on the return to then create an updateitems function for each item you want to update. Again, this is only feasible if you can't use a CAML query on a batch update.

0

I don't think it is available wihtout a Batch update.

0

I believe you'd have to query the list with your CAML query, then iterate through the results with your updates. That said, I did engage Marc to see if he can get you a formal answer on this.

0

SharePoint doesn't appear to natively support updating items based on a query at all, even using SPWeb.ProcessBatchData(). Quite a limitation, given the performance of trying to update each item by ID (even if it's with one big batch statement).

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.