- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2023 06:19 PM
I have a requirement to only display a related list on a form when the logged in user has a specific role. I've tried to do the following in a UI Policy as well as an onLoad Client Script, but the list always appears even if the current user doesn't have the specified role.
Client Script:
function onLoad() {
if (g_user.hasRole('cat_man')) {
g_form.showRelatedList('REL:dfb2edae1b50e51069fecddf034bcbc7');
}
else {
g_form.hideRelatedList('REL:dfb2edae1b50e51069fecddf034bcbc7');
}
}
UI Policy Script:
//execute if true
function onCondition() {
if (g_user.hasRole('cat_man')) {
g_form.showRelatedList('REL:dfb2edae1b50e51069fecddf034bcbc7');
}
//execute if false
function onCondition() {
g_form.hideRelatedList('REL:dfb2edae1b50e51069fecddf034bcbc7');
}
The goal of course is to only allow specifically roled users to see the related list, and I will also need to do the same with some form sections. What is the best way to do this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2023 06:28 PM
Hi @Marcel H_ ,
It seems you've coded it correctly
I would suggest to go for alerts to check whether the code is working perfectly or not
If the alerts are not entering then go for g_user.hasRoleExactly('cat_man')
function onLoad() {
alert("Triggered onload Client Script");
if (g_user.hasRole('cat_man')) {
alert("satisfied the role condition");
g_form.showRelatedList('REL:dfb2edae1b50e51069fecddf034bcbc7');
}
else {
alert("did not satisfied the role condition");
g_form.hideRelatedList('REL:dfb2edae1b50e51069fecddf034bcbc7');
}
}Let me know if you are getting the results via hasRole or hasRoleExactly in the correct way. Will try to resolve from there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2023 06:28 PM
Hi @Marcel H_ ,
It seems you've coded it correctly
I would suggest to go for alerts to check whether the code is working perfectly or not
If the alerts are not entering then go for g_user.hasRoleExactly('cat_man')
function onLoad() {
alert("Triggered onload Client Script");
if (g_user.hasRole('cat_man')) {
alert("satisfied the role condition");
g_form.showRelatedList('REL:dfb2edae1b50e51069fecddf034bcbc7');
}
else {
alert("did not satisfied the role condition");
g_form.hideRelatedList('REL:dfb2edae1b50e51069fecddf034bcbc7');
}
}Let me know if you are getting the results via hasRole or hasRoleExactly in the correct way. Will try to resolve from there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2023 07:34 PM
If relying on inherited roles, you could try to do the opposite, block those that have a higher role. g_user.hasRole('cat_man') == true && !g_user.hasRole('admin');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2023 12:35 PM
Using hasRoleExactly() did the trick, and also worked for hiding a form section using the same role criteria. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2023 11:47 PM
I tried using g_form.showRelatedList('task_sla'); on my instance and it seemed to work. g_form.showRelatedList(<table name of the related list>);