9

I am trying to add menu options to the Command Bar and the List Item context (ECB) menu in OneDrive for Business.

To do this I'm following the same patterns I use when adding menu options to the Command Bar and the ECB menu in a modern document library.

Here's the element manifest for the menu item custom action:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction Id="16b33d61-1e33-49dd-9f00-e52cb7224c4c.BasicMenuItemCustomAction"
                RegistrationType="List"
                RegistrationId="700"
                Location="EditControlBlock"
                Sequence="10001"
                Title="Basic Menu Item Custom Action">
    <!-- 
    Update the Url below to the page you want the custom action to use.
    Start the URL with the token ~remoteAppUrl if the page is in the
    associated web project, use ~appWebUrl if page is in the app project.
    -->
    <UrlAction Url="~appWebUrl/Pages/CustomAction.html?{StandardTokens}&amp;SPListItemId={ItemId}&amp;SPListId={ListId}" />
  </CustomAction>
</Elements>

And here's the element manifest for the ribbon custom action:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction Id="689ee5a9-1343-42da-851c-74100b2fd30a.BasicRibbonCustomAction"
                RegistrationType="List"
                RegistrationId="700"
                Location="CommandUI.Ribbon"
                Sequence="10001"
                Title="Invoke &apos;BasicRibbonCustomAction&apos; action">
    <CommandUIExtension>
      <!-- 
      Update the UI definitions below with the controls and the command actions
      that you want to enable for the custom action.
      -->
      <CommandUIDefinitions>
        <CommandUIDefinition Location="Ribbon.Documents.New.Controls._children">
          <Button Id="Ribbon.Documents.New.BasicRibbonCustomActionButton"
                  Alt="Basic Ribbon Custom Action"
                  Sequence="100"
                  Command="Invoke_BasicRibbonCustomActionButtonRequest"
                  LabelText="Basic Ribbon Custom Action"
                  TemplateAlias="o1"
                  Image32by32="_layouts/15/images/placeholder32x32.png"
                  Image16by16="_layouts/15/images/placeholder16x16.png" />
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler Command="Invoke_BasicRibbonCustomActionButtonRequest"
                          CommandAction="~appWebUrl/Pages/Default.aspx?{StandardTokens}&amp;SPListItemId={SelectedItemId}&amp;SPListId={SelectedListId}"/>
      </CommandUIHandlers>
    </CommandUIExtension >
  </CustomAction>
</Elements>

The only difference between the OneDrive element manifests (shown above) and the document library element manifests is that the RegistrationId is 700 instead of 101.

The menu items show as expected in the document library. The ribbon custom action button shows in the command bar regardless of how many documents are selected in the view. The menu item custom action shows in the ECB menu for each of the items.

Document library ribbon custom action

Document library menu item custom action

The menu items do not show as expected in OneDrive for Business. The ribbon custom action button never shows. At least, I haven't figured out how to get it to show. The menu item custom action shows in the command bar as long as exactly one document is selected. The menu item custom action does not show in the command bar if zero or multiple documents are selected.

OneDrive menu item custom action in the command bar

OneDrive menu item custom action in the command bar

Also, the menu item custom action only shows in the ECB menu for documents after it has been shown in the command bar. That is, only after you open the overflow menu in the command bar.

OneDrive menu item custom action not showing in the EBC menu

OneDrive menu item custom action showing in the EBC menu

I'm looking for some guidance on why the custom actions are behaving differently in OneDrive for Business and document libraries. I'm also looking for guidance on how I get the custom actions in OneDrive for Business to behave more like they do in document libraries. Or, at least, guidance on how to get more control on when and where the menu items appear in OneDrive for Business.

Thanks in advance for your help on this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.