Pergunta

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

Foi útil?

Solução

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

Outras dicas

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

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.

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

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.

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a sharepoint.stackexchange
scroll top