Control Ribbon Visibility (Show/Hide) based on Specific Form in CRM 2011/2013/2015 Multiple Entity Forms
CRM Supports Multiple Forms and we can put ribbon (button in CRM) or Command in the CRM Forms as well.
What if we have requirement to show or hide the ribbon based on Form. In this post I will give example of the code to control ribbon visibility.
Scenario
I have scenario that I have 3 Forms of Account Form.
Now, I want to place a ribbon applicable for Account Form, but only for Partner Form. So when the users are in different form, other than Partner Form, this ribbon should not be available.
The Code
The code is in JavaScript code and it’s pretty simple.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| function controlFormRibbon() { var formLabel; var currForm = Xrm.Page.ui.formSelector.getCurrentItem(); formLabel = currForm.getLabel(); //this code to show the ribbon if only the current opened form is Partner, //otherwise remain disable/hidden if (formLabel == "Partner" ) //change this with your own specific form name { return true ; } else { return false ; } //you can also apply the different/reverse rule here, for example you want to hide if form is Partner } |
Ribbon Workbench Favor
Here, I need a favor from my favorite tool.
I have solution with the ribbon image and script now I just want to place a ribbon and set the JavaScript there.
I create a Button in the Form section, give the Command, rename the Id, assign the Images to the Ribbon.
Then I rename the Label to ‘Partner Only’ that you can see in the final result showing this label Text.
Then Here is the Command.
I apply a Rule here to EnableRules.
This is my rule:
*You can change the Default to True/False to set the default visibility, but in my script I have set other than Partner, will hide this ribbon button, so I don’t bother to change to False.
The key here is just referring the correct FunctionName under the correct Library (your Web Resource where you kept the script) and set parameters if any.
Note: The display rules doesn’t support CustomRule, so just apply it to the EnableRule to show/hide.
Result
I can navigate using Form Selector*My Partner Form
*My Account & Information Forms
As you can see the ribbon is there if I choose the form to Partner, otherwise it’s hidden.
Hope this can help you!
Thank you.