locked
CRM 2011: HIDE custom ribbon button based on user's security role RRS feed

  • Question

  • Hello,

    I have seen numerous posts related to this topic but wanted to be sure about my understanding. I want to HIDE a ribbon button based on user's security role. I know the javascript functions that fetch the user's security role but can I use this  in the <DisplayRule>s to hide the button based on function's output ? Just to be clear - it's NOT to enable/disable. I want the button to disappear and re appear based on the security role.

    so far, when I try to use the display rule to use javascript using something like below, the system gives me an error message while importing - saying that the xml is invalid. 

    <DisplayRule Id ="Appointment.DisplayRuleNew">
                  <CustomRule FunctionName ="checkUserRole" Library="$webresource:Main.js"/>
    </DisplayRule>
    Please help, is there a way to hide using javascript function output ?

    

    Monday, October 8, 2012 11:27 AM

Answers

All replies

  • Hi Rajesh,

    You cannot use  <CustomRule /> in DisplayRule."CustomRule" is used under <EnableRule>.

    That is the reason its giving you the invalid XML error message.

    You can use following rules only in <DisplayRules>

    <RuleDefinitions>
     <DisplayRules>
      <DisplayRule 
       Id="String">
       <CrmClientTypeRule />
       <CrmOfflineAccessStateRule />
       <CrmOutlookClientTypeRule />
       <CrmOutlookClientVersionRule />
       <EntityPrivilegeRule />
       <EntityPropertyRule />
       <EntityRule />
       <FormEntityContextRule />
       <FormStateRule />
       <MiscellaneousPrivilegeRule />
       <OrganizationSettingRule />
       <OrRule />
       <OutlookRenderTypeRule />
       <OutlookVersionRule />
       <PageRule />
       <ReferencingAttributeRequiredRule />
       <RelationshipTypeRule />
       <SkuRule />
       <ValueRule />
      </DisplayRule>
     </DisplayRules>
    </RuleDefinitions>

    Modify your Code as below

    <EnableRule Id ="Appointment.EnableRuleRuleNew">
                  <CustomRule FunctionName ="checkUserRole" Library="$webresource:Main.js"/>
    </EnableRule>

    Hope this helps,

    Regards,

    Yusuf

    
    

    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Thanks and Regards, Mohammad Yusuf Ansari http://microxrm.blogspot.in



    Monday, October 8, 2012 12:20 PM
  • Hi,

    I think you can find the solution in this thread: http://social.microsoft.com/Forums/uk/crmdevelopment/thread/1a478fc9-6a56-40c1-acfe-7e834a38a054

    Best regards,

    Andreas


    Andreas Buchinger
    Microsoft Dynamics Certified Technology Specialist
    MCPD: SharePoint Developer 2010

    Monday, October 8, 2012 12:52 PM
  • Hi Rajesh,

    Although you can't directly hide a button based on the user's role - you can use a EntityPrivilegeRule with a custom entity or other entity that you can dedicate to the job of identifying which role the user has assigned.

    Here is how this can be done using the Ribbon Workbench for CRM2011 - a free ribbon editor:

    http://ribbonworkbench.uservoice.com/knowledgebase/articles/76681-hide-a-standard-out-of-the-box-button-based-on-a

    Here is a video that shows a similar process:

    http://blog.customereffective.com/blog/2012/05/managing-activatedeactivate-permissions-of-crm-entities.html

    hth,

    Scott


    Scott Durow
    Read my blog: www.develop1.net/public     Follow Me on Twitter
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Monday, October 8, 2012 1:07 PM
    Answerer
  • Hi Rajesh,

    Although you can't directly hide a button based on the user's role - you can use a EntityPrivilegeRule with a custom entity or other entity that you can dedicate to the job of identifying which role the user has assigned.

    Here is how this can be done using the Ribbon Workbench for CRM2011 - a free ribbon editor:

    http://ribbonworkbench.uservoice.com/knowledgebase/articles/76681-hide-a-standard-out-of-the-box-button-based-on-a

    Here is a video that shows a similar process:

    http://blog.customereffective.com/blog/2012/05/managing-activatedeactivate-permissions-of-crm-entities.html

    hth,

    Scott


    Scott Durow
    Read my blog: www.develop1.net/public     Follow Me on Twitter
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Thanks everyone for the replies.

    Scott, thank you for the idea about Entityprivilege rule. I can't use that because I want my business logic based around the 'Owner' of the record rather than the currnetly logged in user.

    Anyway, I found a workaround to use the DOM based javascript to hide the ribbon item - using some timeInterval option or something like that. But i didn't go with that either because it's tricky and to be honest unsupported. I finally had to stick with the Enable/disable options instead of hiding.

    Tuesday, October 9, 2012 11:14 AM