Thursday 5 February 2015

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.

image

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.

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.

image

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.

image

I apply a Rule here to EnableRules.

This is my rule:

image

image

*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

image

*My Partner Form

image

*My Account & Information Forms

image












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.

11 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. I tried using this method and at one time I think it initially worked, but after making some additional changes within CRM, it stopped working. It took me a while to figure out the problem. Read https://social.microsoft.com/Forums/en-US/df1f3680-13e8-4a80-ae33-aec16dc89497/crm-2011-get-form-name-using-javascript?forum=crmdevelopment which further down says that Xrm.Page.ui.formSelector.getCurrentItem() only works in certain conditions. If a user only has access to one form, this does not work.

    I've not found a similar solution that does work, though. In my instance the user's I'm trying to control the ribbon visibility for only use this one entity form anyway and they all have a custom security role in common, so I'm just going to create a custom entity that this role has access to and use a 'Entity Privilege Rule' to that entity to show/hide buttons.
    https://ribbonworkbench.uservoice.com/knowledgebase/articles/76681-hide-a-standard-out-of-the-box-button-based-on-a

    It was either this or create a custom field on the form as suggested in the discussion I linked to.

    This blog comment section really needs an edit button. :P

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. why this isn't work in dinamic crm2016 ?

    ReplyDelete
  5. Ooh love this idea! It's awesome! You can get ribbons with 196 colors and 19 sizes for choice from Yama Ribbon!

    ReplyDelete
  6. I am completely inspired with the accurate change aptitude of creator utilized for changing his contemplations and exhibited here. Inspired with profound importance of this article. programa para baixar musica

    ReplyDelete

  7. This post is really nice and informative. The explanation given is really comprehensive and informative.I want to inform you about the salesforce business analyst training and video tutorials . thankyou . keep sharing..

    ReplyDelete
  8. Thanks for the blog loaded with so many information. Stopping by your blog helped me to get what I was looking for. sales automation crm

    ReplyDelete
  9. I got here much interesting stuff. The post is great! Thanks for sharing it! Examen Oficial Linux

    ReplyDelete
  10. This is an excellent post I seen thanks to share it. It is really what I wanted to see hope in future you will continue for sharing such a excellent post. call center solutions in Nigeria

    ReplyDelete

My Name is..