Skip to content

Hide a standard 'out of the box' button based on a users security roles

How To: Hide a standard 'out of the box' button based on a users security roles

Problem:

 "I don't want some of my users having access to the Contact 'Process' Ribbon Group unless they have Organisation Level 'Delete' priviledges on the Contact Entity."

Solution:

The visibility of Ribbon Buttons is controled via it's associated Command. You will recall from 'Getting started with the Ribbon Workbench' that Commands are separate to Buttons so that more than one button can use the same command.

Using the Ribbon Workbench for CRM2011 it is easy to customise an 'out of the box' command and add a Display Rule so that it will not be displayed unless the current user has a specific priviledge on a particiular entitiy.

The key to this solution is that in order to hide a group, you must hide all of the buttons within that group - so this solution is applicable to both hiding a group or just an individual button.


1. Load the Contact entity into the Ribbon Workbench.
2. Select the Run Workflow button →  Right Click → Customise Command



3. Locate the Mscrm.RunWorkflowSelected Command in the ‘Solution Elements’ Panel
4. Right Click →  Edit Display Rules



5. Click ‘+Add New’ and change the Id to be something like:

new.contact.CanDeleteContact.DisplayRule

TIP: Remember that the 'new' part of the default ID is controlled by the solution prefix. I recommend only changing the middle part for consistency.


6. Click ‘Add Step’ and select the Entity Privilege Rule.



7. Set the Step Properties as follows:
     EntityName: contact
     PrivilegeDepth: Global
     PrivilegeType: Delete

TIP: You could change the leve to 'User' if you wanted to have finer control - or even change the entity to a 'dummy' entity so that you had explicit control over who had access to the buttons.



8. Repeat the process for the Start Dialog Button.
9. Select the ‘Start Dialog’ Button → Right Click → Customise Command



10. Locate the Mscrm.RunInteractiveWorkflowSelected Command → Right Click → Edit Display Rules



11. Select the CanDeletecontact Display Rule and click ‘Add>’


12. Click Ok and then publish the solution


This will hide the Process Group on the Home Page Ribbon for Contacts. You must also repeat the steps for the 'Form' and 'Sub Grid' entity by selecting the ‘Form’ and ‘SubGrid’ ribbon types using the Drop down on the top right of the Ribbon Design Panel.

The finished Ribbon Xml will look something like:

<?xml version="1.0" encoding="utf-16"?>
<RibbonDiffXml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<CustomActions />
<Templates>
<RibbonTemplates Id="Mscrm.Templates" />
</Templates>
<CommandDefinitions>
<CommandDefinition Id="Mscrm.RunWorkflowSelected">
<EnableRules>
<EnableRule Id="Mscrm.SelectionCountAtLeastOne" />
<EnableRule Id="Mscrm.RunWorkflowSelected" />
<EnableRule Id="Mscrm.VisualizationPaneNotMaximized" />
</EnableRules>
<DisplayRules>
<DisplayRule Id="new.contact.CanDeleteContact.DisplayRule" />
</DisplayRules>
<Actions>
<JavaScriptFunction FunctionName="Mscrm.GridRibbonActions.launchOnDemandWorkflow" Library="/_static/_common/scripts/RibbonActions.js">
<CrmParameter Value="SelectedControl" />
<CrmParameter Value="SelectedControlSelectedItemReferences" />
<CrmParameter Value="SelectedEntityTypeCode" />
<StringParameter Value="" />
</JavaScriptFunction>
</Actions>
</CommandDefinition>
<CommandDefinition Id="Mscrm.RunInteractiveWorkflowSelected">
<EnableRules>
<EnableRule Id="Mscrm.SelectionCountExactlyOne" />
<EnableRule Id="Mscrm.RunWorkflowSelected" />
<EnableRule Id="Mscrm.VisualizationPaneNotMaximized" />
</EnableRules>
<DisplayRules>
<DisplayRule Id="new.contact.CanDeleteContact.DisplayRule" />
</DisplayRules>
<Actions>
<JavaScriptFunction FunctionName="Mscrm.GridRibbonActions.runScript" Library="/_static/_common/scripts/RibbonActions.js">
<CrmParameter Value="SelectedControlSelectedItemReferences" />
<CrmParameter Value="SelectedEntityTypeCode" />
</JavaScriptFunction>
</Actions>
</CommandDefinition>
</CommandDefinitions>
<RuleDefinitions>
<TabDisplayRules />
<DisplayRules>
<DisplayRule Id="new.contact.CanDeleteContact.DisplayRule">
<EntityPrivilegeRule PrivilegeType="Delete" PrivilegeDepth="Global" EntityName="contact" />
</DisplayRule>
</DisplayRules>
<EnableRules>
<EnableRule Id="Mscrm.SelectionCountAtLeastOne">
<SelectionCountRule AppliesTo="SelectedEntity" Minimum="1" />
</EnableRule>
<EnableRule Id="Mscrm.RunWorkflowSelected">
<CustomRule FunctionName="Mscrm.GridRibbonActions.enableWorkflowOnGrid" Library="/_static/_common/scripts/RibbonActions.js">
<CrmParameter Value="SelectedControl" />
</CustomRule>
</EnableRule>
<EnableRule Id="Mscrm.VisualizationPaneNotMaximized">
<CustomRule FunctionName="Mscrm.RibbonActions.disableButtonsWhenChartMaximized" Library="/_static/_common/scripts/RibbonActions.js">
<CrmParameter Value="SelectedControl" />
</CustomRule>
</EnableRule>
<EnableRule Id="Mscrm.SelectionCountExactlyOne">
<SelectionCountRule AppliesTo="SelectedEntity" Minimum="1" Maximum="1" />
</EnableRule>
</EnableRules>
</RuleDefinitions>
<LocLabels />
</RibbonDiffXml>

Feedback and Knowledge Base