MSDN Article for CommandUIHandler Element

Applies to: SharePoint Foundation 2013 | SharePoint Server 2013

In this article
Child Elements
Parent Elements

Defines the handler for a command.

  Command = "Text"
  CommandAction = "Text"
  EnabledScript = "Text"

Attribute Description
Command Required. The name of a command. The value of this attribute matches the value of a Command attribute on an element that defines a control.
CommandAction Required. A script statement to execute when this handler is invoked. Microsoft SharePoint Foundation calls theeval method, passing in the value of this attribute.

The value of the attribute can contain substitution tokens that are transformed at rendering. The following tokens are recognized:

  • {ItemId} – ID (GUID) taken from the list view.
  • {ItemUrl} – Web-relative URL of the list item (Url).
  • {RecurrenceId} – ID of a recurrent item (RecurrenceID).
  • {SiteUrl} – The fully qualified URL to the site (Url).
  • {ListId} – ID (GUID) of the list (ID).
  • {ListUrlDir} – Server-relative URL of the site plus the list’s folder.
  • {Source} – Fully qualified request URL.
  • {SelectedListId} – ID (GUID) of the list that is currently selected from a list view.
  • {SelectedItemId} – ID of the item that is currently selected from the list view.
EnabledScript Optional.

Note Note
The EnabledScript attribute doesn’t work on custom actions deployed to the host web by an app for SharePoint.

A script statement that is executed to determine whether the command is enabled or disabled. The script expression should return a Boolean value, true if the command is enabled and false if not. If the ribbon is disabled, commands are grayed out and are not clickable.

As with the CommandAction attribute, the eval method is called with the value of this attribute as an argument. The EnabledScript attribute does not support the substitution tokens that are described for the CommandActionattribute.

Minimum: 1

Maximum: unbounded

The following example defines a button command and a corresponding handler.

<Elements xmlns="">
           function getItemIds()
             var itemIds = '';
             var items = SP.ListOperation.Selection.getSelectedItems();
             var item;
             for(var i in items)
               item = items[i];
               if(itemIds != '')
                 itemIds = itemIds + ',';
               itemIds = itemIds +;
             return itemIds;
           function handleReadyStateChange()
             if (client.readyState == 4)
               if (client.status == 200) 
                 // client.responseText is mailto string
                 window.location = ('mailto:' + client.responseText);
           function invokeEmailContacts()
             var params = 'itemids=' + getItemIds(); 
             // Posting to EmailContacts.ashx to get the mailto string
             var site='{SiteUrl}'; 
             var url = site + '/_layouts/emailcontacts.ashx?listId={ListId}';
             client = null;
             client = new XMLHttpRequest();
             client.onreadystatechange =  handleReadyStateChange;
   'POST', url, true);         
             client.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
             client.setRequestHeader('Content-length', params.length);
           function enableEmailContacts()
             var items = SP.ListOperation.Selection.getSelectedItems();
             return (items.length > 0);

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: