I blogged about the awesome SPServices library before. This time, I needed another functionality of this jquery lib: SPUpdateMultipleListItems.
What this does is let you make a query to select one or more items in a list and give you the power to update some fields (or delete items).
That is just great. Imagine you need to find and update 200 documents about a project that is now in a different status or has a new manager or whatever. This function can make that happen.
Another great use for it is to update the content type of more items on the same time. This is not possible in SharePoint out-of-the-box, but with the SPUpdateMultipleListItems it is a piece of cake.
The code
<script type="text/javascript"> $(document).ready(function() { $("#btnChangeCT").click(function(){ $().SPServices.SPUpdateMultipleListItems({ listName: "System documents", CAMLQuery: "<Query><Where><Eq><FieldRef Name='Status'/><Value Type='Text'>Inactive</Value></Eq></Where></Query>", valuepairs: [["ContentType", "Report"]] }); }); </script> <input type="button" id="btnChangeCT" value="Modify CT" />
This code creates a button. If you click on it, all documents in the Shared Documents library with the status “Inactive” will get a new contenttype.
Easy right ? The CAML query gives you the power to filter on any metadata field, the valuepairs allow you to update any metadata field you want.
As always, don’t forget a reference to the jquery library and the SpServices library !
Big thanks to Marc Anderson (@sympmarc) and Sven De Bont (@SvenDeBont) for helping me with this one.
is it possible to do a auto-increment a value of a listitem column by using the above class/operation
you probably can!