Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Answered

Load a form "Tab" based on Security Role

Posted on by 285

Hi Everyone,

I am trying to Load a tab based on the Security role. Can anyone please help? 

I tried using the below code on the form onLoad but no luck.

Can anyone please correct me?? or provide a better solution.

For below code; i used onload function "leadFormCustomization.customEditAccess"

 

var leadFormCustomization = {

customEditAccess: function (execContext) {
debugger;
var formContext = execContext.getFormContext();
var userSettings = Xrm.Utility.getGlobalContext().userSettings;

//Get Security Roles of the current User
var securityRoles = userSettings.securityRoles;

//Below is the GUID of the Security Role "CustomEditAccess"
var securityRoleId = "7b54873B06-A234-EA11-A812-000D3A53014B";


for (i = 0; i < securityRoles.length; i  ) {
//If current User contains the Required Security Role
if (securityRoles[i].toUpperCase() == securityRoleId.toUpperCase()) {
		
		Xrm.Page.ui.tabs.get("tab_2").setFocus()

}}}}


Thank you in advance.

  • nidnani Profile Picture
    nidnani 285 on at
    RE: Load a form "Tab" based on Security Role

    Hi, can you please take a look a look at this issue? It is similar to this one.

    community.dynamics.com/.../show-sp-documents-subgrid-based-based-on-security-role

  • Verified answer
    mobeenmohsin Profile Picture
    mobeenmohsin on at
    RE: Load a form "Tab" based on Security Role

    Hi,

    We should use getGlobalContext.userSettings (Client API reference) in model-driven apps - Power Apps | Microsoft Docs roles which have name and you can compare with name instead of GUID as it is readable information for future tracking and future identification of issue quickly. Microsoft deprecated securityRoles method so we must use the userSettings.roles method to avoid any issue.

    Please find more information as below about userSettings.roles

    roles

    Returns a collection of lookup objects containing the GUID and display name of each of the security role assigned to the user and any security roles assigned to a team that the user is associated with. This method is supported only on Unified Interface.

    Microsoft introduced this method in UCI and it should be used as Microsoft advised as below:

    securityRoles

    Returns an array of strings that represent the GUID values of each of the security role or teams that the user is associated with.

    Deprecated; use userSettings.roles instead to view the display names of security roles or teams along with the ID.

    So, please use userSettings.roles method and compare with name instead of ID. Thank you.

    Best Regards,

    Mobeen Mohsin

  • nidnani Profile Picture
    nidnani 285 on at
    RE: Load a form "Tab" based on Security Role

    Thank you so much, Mehran. It's working fine. Appreciate your help! :)

  • Verified answer
    MehranBre Profile Picture
    MehranBre 730 on at
    RE: Load a form "Tab" based on Security Role

    Hello

    I think you made a very, very small mistake!

    Note this line:

     var securityRoleId = "7b54873B06-A234-EA11-A812-000D3A53014B"

    Looks like you copied the GUID incorrectly and added 7b in the first one!

    True: "54873B06-A234-EA11-A812-000D3A53014B"

    best regards.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans