Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Hide an action from Form ribbon to specific security roles

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi,

We have this button "Calificar" (Convert to lead, or "Qualify" button)  in our Lead entity form:

We have also the user roles in: Configuration> Security > Security Roles 

We need to "hide" the previous button for specific user roles. I tried with Ribbon Workbench by following this guide but I wasn't able since it is explained for privilege types.

*This post is locked for comments

  • Suggested answer
    Ziv Profile Picture
    Ziv 5 on at
    RE: Hide an action from Form ribbon to specific security roles

    Hi Martin

    Unfortunately, you can't use the 'Xrm.WebApi' library in your ribbon enable\display role.

    The 'Xrm.WebApi' runs asynchronous so the function return undefined to the Ribbon before the answer gets back from the callback function.

    Alternatively, you can use XmlHttpRequest.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Hide an action from Form ribbon to specific security roles

    , thank you for replying. I made this script after following your step-by-step guide...

    functionCheckSecurityRoles() {
    	var allowedRoles = arguments;
    	var loggedUserRoles = Xrm.Page.context.userSettings.securityRoles;
    	
    	Xrm.WebApi.retrieveMultipleRecords("roles", "?$select=name,roleid").then( function success(result) {
    		if(result.entities.length > 0 && allowedRoles.length > 0) {
    			var totalRoles = result.entities;
    			var existingRoles = new Array();
    			var userHasAccess = false;
    			
    			for(var allowedRolesIndex = 0; allowedRolesIndex < allowedRoles.length; allowedRolesIndex++) {
    				for(var totalRolesIndex = 0; totalRolesIndex < totalRoles.length; totalRolesIndex++) {
    					if(allowedRoles[allowedRolesIndex].toLowerCase() === totalRoles[totalRolesIndex].name.toLowerCase()) {
    						existingRoles.push(totalRoles[totalRolesIndex]);
    					}
    				}
    			}
    			
    			if(existingRoles.length > 0) {
    				for(var loggedUserRolesIndex = 0; loggedUserRolesIndex < loggedUserRoles.length; loggedUserRolesIndex++) {
    					for(var existingRolesIndex = 0; existingRolesIndex < existingRoles.length; existingRolesIndex++) {
    						if(loggedUserRoles[loggedUserRolesIndex] === existingRoles[existingRolesIndex].roleid) {
    							userHasAccess = true;
    						}
    					}
    				}
    			}
    			return userHasAccess;
    		}
    	});
    }]
    


    This works on the Developer tool on Chrome, but... what's next? I added some parameters for testing purposes in the Ribbon Workbench and it works... but the button is still there. Even if I try to create a function with `return true` as the only line.

  • Verified answer
    gdas Profile Picture
    gdas 50,089 on at
    RE: Hide an action from Form ribbon to specific security roles

    Hi Martin,

    You are doing right just you  need to create a Javascript Web Resource where you will put your javascript function .  To create web resource go to Settings --> Customization--> Customize the System/Solution --> expand solution component --> Web Resources --> Create New Javascript web resource.

    Once you create webResource you can select your webresource  from the ribbon workbench "Library" dropdown  here in your screenshot  (Make sure the solution you are opening Ribbon workbench  should include  the webresource)

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Hide an action from Form ribbon to specific security roles

    Ben Thompson, I guess that would be combined to  answer. My question would be where should I have to include that Javascript. I probably found where to create and attach the function to the ribbon, but not where to upload the JS library:

    Regarding to Shahbaaz Ansari's answer, that was I mentioned in my question. Thanks anyway.

  • Suggested answer
    Shahbaaz Ansari Profile Picture
    Shahbaaz Ansari 6,205 on at
    RE: Hide an action from Form ribbon to specific security roles

    HI Martin,

    This should definitely work, ribbonworkbench.uservoice.com/.../76681-hide-a-standard-out-of-the-box-button-based-on-a

    Please try to follow each steps mention in above link, i have also used it and it was working.

    Best Regards,

    Shahbaaz

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Hide an action from Form ribbon to specific security roles

    You can use Ribbon Workbench and set the Privileges for the button that you want to hide (either Entity Privileges or Miscellaneous Privilege).

    If you need to set it only for a particular role, add some privilege to that role, and use either of the two privileges I mentioned.

    Hope this helps.

  • Suggested answer
    gdas Profile Picture
    gdas 50,089 on at
    RE: Hide an action from Form ribbon to specific security roles

    Hi Martin,

    You need to implement enable rule in ribbon workbench with custom javascript rule.

    In the javascript function simply get the user roles and check whether if particular role user having then return false, it will hide the button.

    Here is reference how to get roles for login user.

    community.dynamics.com/.../229425

    Enable rule with javascript-

    www.magnetismsolutions.com/.../how-to-use-enable-rules-in-dynamics-365-with-the-ribbon-workbench

    Hope this helps.

  • Suggested answer
    Ben Thompson Profile Picture
    Ben Thompson 6,350 on at
    RE: Explicitly hiding "Convert Lead" button from the "Lead" entity form to specific security roles.

    You will need to control the button via a piece of Javascript that checks the security roles a user has and shows / hides the button based on the roles returned.

    Assuming you are using version 9 you can use var roles = globalContext.userSettings.securityRoles(); to get an array of the Guids of roles the user has otherwise use var roles =Xrm.Page.context.getUserRoles();

    Then run a check against the guids and return true or false to the display or enable function you are using to control the button. I recommend just using the security role guids as it saves a secondary query to get the names of the security roles.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,307 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans