web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Load a form "Tab" based on Security Role

(0) ShareShare
ReportReport
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.

I have the same question (0)
  • Verified answer
    MehranBre Profile Picture
    732 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.

  • nidnani Profile Picture
    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
    mobeenmohsin Profile Picture
    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
    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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 125

#2
Tom_Gioielli Profile Picture

Tom_Gioielli 101 Super User 2025 Season 2

#3
Erin Lubben Profile Picture

Erin Lubben 57

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans