I am deploying custom ribbon button using SharePoint provider hosted app. I was able to show button where I wanted but not able to control enable or disable state of the button. It remains active regardless of list item selected or not.

Here is custom control xml for the ribbon button,

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction Id="33080663-4c4a-457f-aae5-d2185039bdb5.RibbonCustomAction_ConvertPDF"
                Title="Convert to PDF">
      Update the UI definitions below with the controls and the command actions
      that you want to enable for the custom action.
        <CommandUIDefinition Location="Ribbon.Documents.Copies.Controls._children">
          <Button Id="Ribbon.Documents.Copies.RibbonCustomAction_ConvertPDFButton"
                  Alt="Convert to PDF"
                  LabelText="Convert to PDF"
                  TemplateAlias="o1" CommandType="OptionSelection"
                  Image16by16="~SiteCollection/SiteAssets/Muhimbi/pdf16.gif" />
        <CommandUIHandler Command="Invoke_RibbonCustomAction_ConvertPDFButtonRequest"
                          EnabledScript="javascript:function multiEnable() {  var items = SP.ListOperation.Selection.getSelectedItems(); return (items.length > 0); } multiEnable();" />
    </CommandUIExtension >

In on-premise deployment, we handle "EnabledScript" event to control enable/disable state of the button. I have done exactly what I used to do before but it's not working. I have also tried to put just alert('') to check if the event is firing but looks like "EnabledScript" event is not firing at all.

  • I was looking for this solution a few weeks ago, and I found a post somewhere that Microsoft disabled this in SharePoint Online (I'm in SPO as well). I will try to find the link and post it.
    – wjervis
    Commented Dec 18, 2014 at 13:51

1 Answer 1


According to MSDN (search for CustomAction on page) you are not allowed to put Javascript in a CommandAction, only URLs are expected there.

But as it turned out you still can add custom action with JavaScript in CommandAction and with EnabledScript attribute using JSOM or SSOM. Check this example, it works for me.

  • 1
    I like the plot twist. :D Commented Nov 21, 2018 at 21:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.