Add button to Sub Grid - but only when on a specific parent entity

The Ribbon Workbench for CRM 2011 makes it easy to add a ribbon button to SubGrid ribbons. Your new custom button will be always shown when you have selected a subgrid on a related (1:N) entity parent entity form. Of course entities can have more than one relationship and so the same SubGrid ribbon is displayed from lots of different places. An example of this is the 'Account->Contact' and 'Contact->Sub-Contact' relationships. If you click on Contacts from an Account form, you will get the same Contact SubGrid ribbon as if you click on Sub-Contacts from the Contact Form. This may be fine, but what happens if you want to show different buttons on these two ribbons? Suppose you had a function that was only needed for Contact Sub-Contacts, but not for Account-Contacts? In this situation, the FormEntityContextRule is your friend.

The following tutorial show how to make a button visible only on the Contact->Sub-Contacts SubGrid, but not the Account->Contacts ribbon. It starts by first adding a button that appears on both, then an DisplayRule is added using the FormEntityContextRule to control the visibility.


The resulting Xml would be:

    <CustomAction Id="" Location="" Sequence="60">
        <Button Command="" Id="" Image32by32="$webresource:new_Image32.png" Image16by16="$webresource:new_Image16.png" LabelText="$" Sequence="60" TemplateAlias="o1" />
    <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>
    <CommandDefinition Id="">
      <EnableRules />
        <DisplayRule Id="" />
        <Url Address="about:blank" WinMode="1" />
    <TabDisplayRules />
      <DisplayRule Id="">
        <FormEntityContextRule EntityName="contact" />
    <EnableRules />
    <LocLabel Id="">
        <Title description="SubGrid Button" languagecode="1033" />


If course, you could use an OrRule to add multiple conditions to make it appear on multiple parent forms, but not all of them. This would change your rule to be:

<DisplayRule Id="">
          <FormEntityContextRule EntityName="contact" />
          <FormEntityContextRule EntityName="account" />

I hope you agree that using the Ribbon Workbench can shave hours off of your development time when customising the CRM2011 Ribbon!

The Ribbon Workbench for CRM 2011 is a free download.

If you find an issue with the Ribbon Workbench for Dynamics CRM 2011 or have any suggestions, please send it here

Happy Ribbon Customising!

Pingbacks and trackbacks (1)+

Comments are closed