Crm Newshubb
Advertisement
  • Home
  • News
  • CRM Software & Tools
  • Contact us
No Result
View All Result
  • Home
  • News
  • CRM Software & Tools
  • Contact us
No Result
View All Result
Crm Newshubb
No Result
View All Result
Home CRM Software & Tools

Show/Hide a custom button based on Security Role using JavaScript

admin by admin
January 6, 2023
in CRM Software & Tools


This blogpost demonstrates how a maker can implement show/hide logic on a custom ribbon button in a model-driven app based on a user’s security roles. This functionality can be useful if we want to restrict access to a ribbon button that performs sensitive or business critical operations because without the proper security role, a user won’t be able to click the restricted ribbon button to launch the process or execute the logic.  

Requirement: 

We want to show the ribbon button to only users who have been assigned to “Basic User” security role.  Note: While this functionality can be implemented for any security role in your Dynamics 365 instance (custom as well as out-of-box), we will use the Basic User role in this example. 

If the logged-in user has been assigned this role, they should be able to see the Invoice button, as shown in the example below. If they have note been assigned the role, they won’t see the button. 

Solution: 

JavaScript Code 

Here we will use JavaScript code to check the assigned security role of the logged-in user. 

Create a new web resource in your solution and add the below piece of code in your JavaScript. 

In this code, the Primary Control (context) will be passed from ribbon workbench enable rule.  

Also, to get the user’s security roles we have used context._globalContext._userSettings.roles; which returns collection of objects – with GUID and name of each security role that is assigned to the user individually or through a team. We are comparing the role with the name field. 

We could also use context._globalContext._userSettings.securityRoles; (which is used to return an array of GUID values of each security role), as illustrated in Example 2 below.

However, we would then need to compare the role with the security role’s GUID – which must be hardcoded and can change in other environments/instances. Since name could remain the same in all instances, it may be easier to utilize context._globalContext._userSettings.roles, as shown in Example 1 above. 

Either way, the JavaScript code will return TRUE if user has certain role and FALSE if not. 

Ribbon Button – Enable Rule 

The next step to complete our show/hide functionality utilizes the XRM toolbox. This is an open-source tool that is very useful for CRM and Power Platform development. You may also need to install the Ribbon workbench in your instance of XRM toolbox if you have not already. 

 In the Ribbon Workbench below is the form Invoice Button on which the “poc.account.Command.InvoiceForm” command is called. 

We add a new Enable Rule in which we add a CustomRule to call our JavaScript code and pass the record’s PrimaryControl. 

The CustomRule we have applied will call the JavaScript function and is expected to receive either true or false based on the code. 

If TRUE – button will be enabled 

If FALSE – button will not be enabled 

Make sure to add this Enable Rule to the command (which is in-turn attached to the Ribbon Button itself). 

Hope this has been helpful. For more Dynamics 365 tips and tricks, follow our blog!  Happy Dynamics 365’ing! 



Source link

Previous Post

Vtiger CRM Blog » Power 2023 with the feature-rich Vtiger CRM & see your productivity soar

Next Post

How Real-time GPS tracking of Field Reps improves Individual and Sales Performance – CRM Software Blog

Next Post

How Real-time GPS tracking of Field Reps improves Individual and Sales Performance - CRM Software Blog

Recommended

Vtiger CRM Blog » 9 Reasons Why You Should Dress Well For Work

November 24, 2022

How BDRs and Marketing Create Nurture Campaigns

August 16, 2022

5 Can’t Miss SugarClub Posts from November 2022

December 8, 2022

Hide/Show System Views in Dynamics 365 – CRM Software Blog

October 5, 2022

Don't miss it

News

5 Features That Make Sugar Sell’s Forecasting Better

January 31, 2023
News

Vtiger CRM Blog » CRM Trends of 2023: Social CRM

January 31, 2023
CRM Software & Tools

Explore new markets with Census Data and Land Area Mapping with maps integration within Microsoft Dynamics 365 CRM – CRM Software Blog

January 30, 2023
CRM Software & Tools

Streamline Business Operations with Microsoft Dynamics 365 CRM and Power Platform Development Services by Inogic! – CRM Software Blog

January 29, 2023
CRM Software & Tools

4 Must Have Features On-field Sales Team Will Use Daily

January 28, 2023
CRM Software & Tools

Training Dynamics 365 Users is a Waste of Time – CRM Software Blog

January 27, 2023

crm-white

© 2022 CRM News Hubb All rights reserved.

Use of these names, logos, and brands does not imply endorsement unless specified. By using this site, you agree to the Privacy Policy and Terms & Conditions.

Navigate Site

  • Home
  • News
  • CRM Software & Tools
  • Contact us

Newsletter Sign Up

No Result
View All Result
  • Home
  • News
  • CRM Software & Tools
  • Contact us

© 2022 CRM News Hubb All rights reserved.