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
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
Note: TabCommand should be same as CommandDefinition Id used under CommandDefinition
Step 7:
Create a new DisplayRule as shown below
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"
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)
After hiding Contextual Ribbon (Note there is NO List Tools Ribbon tab)
Hope this helps
awesome blog mate!
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
Hi Taj,
I think you forget to put your code.
Few things you can try is use Xrm.Page.ui.refreshRibbon()
HTH
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>
Try using all lowercase for field name, that is use new_boola instead on new_BoolA.
I actually used all lower case i.e. new_boola
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 🙂
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.
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?
In that case you have to keep the Grid View “loosely coupled” on Form, you can refer my other blog https://myencounterwithcrm.wordpress.com/2012/01/21/linking-associated-views-from-non-linked-entities/ which explains how to link the Grid view loosely.