Update content type or metadata for multiple items in a list/library in SharePoint 2010 / 2007

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.

About: Marijn

Marijn Somers (MVP) has over 14 years experience in the SharePoint world, starting out with SP2007. Over the years the focus has grown to Office 365, with a focus on collaboration and document management. He is a business consultant at Balestra and Principal Content Provider for "Mijn 365 Coach" that offers dutch employee video training. His main work tracks are around user adoption, training and coaching and governance. He is also not afraid to dig deeper in the technicalities with PowerShell, adaptive cards or custom formatting in lists and libraries. You can listen to him on the biweekly "Office 365 Distilled" podcast.


2 thoughts on “Update content type or metadata for multiple items in a list/library in SharePoint 2010 / 2007”

  1. is it possible to do a auto-increment a value of a listitem column by using the above class/operation

Leave a Reply

Your email address will not be published. Required fields are marked *