How to check for role using g_user.hasRole() in client script independent of instance?

MP22
Giga Contributor

Hi.

I would like to hide a section if the user has a specific role. I currently have a onLoad client script that checks for

If (g_user.hasRole('x_475000_help_desk.end_user')) {

' Code to hide section

}

The hasRole() works only if I pass in the full role name including the 'instance & app name' prefix. As I move my application from dev to test to prod, the instance would change. I don't want to keep change the script every time. I am wondering if I can make this independent of the instance in one of two ways:

1. Is there a way to perform the hasRole() check without using the 'instance & app' prefix? Something like g_user.hasRole('end_user') instead of g_user.hasRole('x_475000_help_desk.end_user').

or

2. Is there a way to dynamically get the instance name in the client script so that I can build the instance-specific role name dynamically? I found ways to get the instance on the server side, but am not sure how to get the instance name in the client script.

Thanks for your help!

1 ACCEPTED SOLUTION

Ashutosh Munot1
Kilo Patron
Kilo Patron

Hi,

The prefix X_475 should not change from instance to instance. This is a scope name of the application.


And yes you need to use full role name as you are using now.

 

Thanks,
Ashutosh

View solution in original post

2 REPLIES 2

Ashutosh Munot1
Kilo Patron
Kilo Patron

Hi,

The prefix X_475 should not change from instance to instance. This is a scope name of the application.


And yes you need to use full role name as you are using now.

 

Thanks,
Ashutosh

MrMuhammad
Giga Sage

Hi MP,

 

When you create role in scoped application it prefix the role with x_scopeNumber_applicationName.

It doesn't include instance name. If you have published or imported application in the TEST and PROD envrionments then there would be no issue all will have same prefix with the role. The only thing could cause an issue if you have created application in each envrionment separately. 

 

Please mark this correct & helpful if it answered your question.

Thanks & Regards,
Sharjeel

Regards,
Muhammad