Thursday, July 17, 2014

Enable or disable ribbon custom action button in SharePoint 2010

Enable or disable ribbon custom action button in SharePoint 2010



<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
  Id="AlertRibbonButton"
  RegistrationId="100"
  RegistrationType="List"
  Location="CommandUI.Ribbon"
  Sequence="5"
  Title="Alert Ribbon Button">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition Location="Ribbon.List.Settings.Controls._children">
          <Button
          Id="AlertRibbonButtonId"
          Alt="Alert Ribbon Button"
          Sequence="5"
          Command="AlertRibbonButton"
          Image32by32="/_layouts/images/menulistsettings.gif"
          Image16by16="/_layouts/images/itdcl.gif"
          LabelText="Alert Ribbon Button"
          TemplateAlias="o1" />
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler
        Command="AlertRibbonButton"
        EnabledScript="javascript:        
        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 + item.id;
             }     
             alert(itemIds);
           }                        
          var EnableDisable = function() {
          this.clientContext = SP.ClientContext.get_current();
          this.selectedItems = SP.ListOperation.Selection.getSelectedItems(this.clientContext);
          var ci = CountDictionary(selectedItems);       
          return (ci > 0);
          //return (ci == 1); //if we want enable for one item only
        };
        EnableDisable();"
        CommandAction="javascript: alert('Hi Alert!');" />
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>
</Elements>

No comments:

Post a Comment

Featured Post

Mention a Channel or Team – Power Automate

Mention a Channel or Team – Power Automate graph.microsoft.com/v1.0/teams/{teamId}/channels/{channelId}/messages Channel: ---------- {   &qu...

Popular posts