CRM 2011–Hiding Ribbon Tab using FormEntityContextRule


CRM 2011 does offer <HideCustomAction> to hide Ribbon Elements including Ribbon tabs. However in some cases we might have to selectively hide Tabs based on several conditions.

In such cases <HideCustomAction> is of less helpful as it globally hides the Ribbon element.

In this Walkthrough I am trying to demonstrate on of such scenario.

Scenario: A CRM Entity form has has Many-To-One relationship with multiple entities. Each of these entities are having Sub-Grid to show CRM entity in List form. Now we wanted to hide Contextual (List) tab for Sub-Grid entity from Main form of some of the entities.

Step 1:

Create a CRM 2011 Solution with entity for which Ribbon in Contextual Tab needs to be hidden. In this case entity name is new_cpvertical

Step 2:

Open ExportRibbonXml for the entity new_cpvertical. You can find this xml at SDK folder samplecodecsclientribbonexportribbonxmlbinDebugExportedRibbonXml. If RibbonXml for your entity is not available you can execute the solution exportribbonxml.sln and create one.

 

Step 3:

In RibbonXml, locate Tab element with Id as “Mscrm.SubGrid.new_cpvertical.MainTab” and copy entire Tab element with all its decendants.

Step 4:

Open customization.xml file from Solution you exported in Step1, and add Tab element copied in Step 3 under

image

Note that Location value for CustomAction is same as MainTab id.

Step 5:

Copy Command="Mscrm.SubGrid.new_cpvertical.MainTab" and all the Rules that has been referenced in Command.

Step 6:

Copy <TabDisplayRules> element under <RuleDefinitions> as shown below

image

Note: TabCommand should be same as CommandDefinition Id used under CommandDefinition

Step 7:

Create a new DisplayRule as shown below

image

Note: EntityName value is name of the PrimaryEntity where Sub-Grid is placed. Depending upon how many such entities need to be configured you can add Or to it.

Step 8:

Call this DisplayRule in Command ="Mscrm.SubGrid.new_cpvertical.MainTab"

image

Step 8:

Save the Customization, zip it back to Solution file and Import solution in CRM and Publish the Customization.

Here is how it looks with Contextual Ribbon hidden

With Contextual Ribbon (Note there is a List Tools Ribbon tab)

image

After hiding Contextual Ribbon (Note there is NO List Tools Ribbon tab)

image

Hope this helps

11 thoughts on “CRM 2011–Hiding Ribbon Tab using FormEntityContextRule

  1. Hi Makarand,

    Thanks for the great post, was really helpful.

    I having some issue while trying to do this.

    My requirement: I need to hide “Activities” menu for a custom entity “new_custom” when a boolean field “new_BoolA” of that custom entity holds a value “false”. I am using the following code:

    Unfortunately above code is not working properly; it hides the Activity menu always.

    Is there anything I am missing?

    Your help will be greatly appreciated!

    Cheers,

    Taj

  2. I am using the following code:

    <CommandDefinitions>
    <CommandDefinition Id="Mscrm.SubGrid.activitypointer.MainTab.Related.Hide">
    <EnableRules />
    <DisplayRules>
    <DisplayRule Id="Mscrm.SubGrid.activitypointer.MainTab.HideRelated" />
    </DisplayRules>
    <Actions />
    </CommandDefinition>
    </CommandDefinitions>
    <RuleDefinitions>
    <TabDisplayRules >
    <TabDisplayRule TabCommand="Mscrm.SubGrid.activitypointer.MainTab.Related.Hide">
    <EntityRule AppliesTo="SelectedEntity" EntityName="activitypointer" />
    </TabDisplayRule>
    </TabDisplayRules>
    <DisplayRules>
    <DisplayRule Id="Mscrm.SubGrid.activitypointer.MainTab.HideRelated">
    <FormEntityContextRule EntityName="new_custom" InvertResult="true" />
    <ValueRule Field="new_BoolA" Value="0" InvertResult="true" />
    </DisplayRule>
    </DisplayRules>
    <EnableRules />
    </RuleDefinitions>

  3. Excellent! Worked like a charm! Thanks for a great post.

    One question though, is it possible to make all the ribbon buttons enabled in “CP Header” and all the other tabs? Because now they are all disabled..

    Thanks 🙂

    1. Thanks for your comments.

      To answer your question, that is default behavior of CRM, whenever you select (focus) the Child entity grid, main entity tool bar becomes disable. If you go back to any tab link (for example General in this case) it will make all the Ribbon enable again.

  4. The problem is that I want to stay in the “CP Verticals” tab and still see all the ribbon buttons enabled in the “Cp Header” section..I can change the ribbon tabs between “CP Header”, “Add” and “Customize”. Maybe there is some “hack” to enable all the ribbon buttons in those sections?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Connecting to %s