Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

share|improve this question
add comment

6 Answers

up vote 2 down vote accepted

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

share|improve this answer
add comment

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.

share|improve this answer
add comment

I am also looking for similar example using Client side Jquery and Web services for updating multiple list items on a button click. Can you help?

share|improve this answer
add comment

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.

share|improve this answer
add comment

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

share|improve this answer
add comment

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

share|improve this answer
    
I only want to use clientside jQuery and SPServices, so your solution is good, but not feasible for me. –  Stef 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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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