Sharepoint 2013 Custom Ribbon Action To Update a List Item Field

In this post I’ll show how to develop a Custom Ribbon Action, that iterates through selected document library (with a custom column named Category) items and updates  a field value (category).

I want to do another post to  get the value from a modal dialog, but for now, the updated value will be hard coded.

I started creating a SharePoint 2013 empty project in Visual Studio 2012 (selected the deployment as a farm solution, but could also be sandbox).

Add a new module to my project called “CustomAction”, and add the following code, to elements.xml file:


<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns=""> 
    Title="MoveDocs Ribbon Button">
          <Button Id="Ribbon.Library.Share.NewRibbonButton"
            TemplateAlias="o2" />
            var context;
            var currentItem ;
          function onQuerySucceededUpdate (sender, args) {
              alert('item updated');

          function onQueryFailedUpdate(sender, args) {
            alert('Error occured' + args.get_message());
          function UpdateCategory(val)
            context = SP.ClientContext.get_current();
            var web = context.get_web();
             var currentlibid = SP.ListOperation.Selection.getSelectedList();
             var currentLib = web.get_lists().getById(currentlibid);
             var selectedItems = SP.ListOperation.Selection.getSelectedItems(context);
             for(var i in selectedItems)
                currentItem = currentLib.getItemById(selectedItems[i].id);
                if(currentItem != null) {
                  currentItem.set_item('Category', val);
                context.executeQueryAsync(Function.createDelegate(this, onQuerySucceededUpdate), Function.createDelegate(this, onQueryFailedUpdate));
              }// End for
          }//End UpdateCategory

  <Module Name="CustomAction">

Tags: ,

2 responses to “Sharepoint 2013 Custom Ribbon Action To Update a List Item Field”

  1. Joe Wilson says :

    Obrigado Raquel, thanks for sharing your Custom Ribbon Action. Hope all’s well in Lisbon.

  2. Rob says :

    Thank you very much for sharing this! I was searching for something very similar for a couple of hours already. Great work!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: