How to check the logged in user is a member of a group and group has a role in client side?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2022 01:32 PM - edited 11-04-2022 01:34 PM
Hi,
I want to display a field 'TeamName' if a current logged in user is a member of current assignment group of an incident and if that group has a role 'roleA'.
How can I achieve this in UI policy? Please provide sample scripts if there is any
Thanks in advance,
Dinesh
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2022 02:37 PM
You are looking for information that requires server-side calls. The main method I have seen to accomplish this is by having a Business Rule that runs on display and populates g_scratchpad variables. Those variables then become available to use in client-type scripts.
//Business Rule: Populate Incident Scratchpad
g_scratchpad.group_member = gs.getUser().isMemberOf(current.assignment_group); //returns true or false
g_scratchpad.group_role = gs.getUser().hasRole('roleA'); //returns true or false
//UI Policy Script execute if true
function onCondition(){
if(g_scratchpad.group_member == 'true' && g_scratchpad.group_role == 'true'){
g_form.setDisplay('TeamName', 'true');
}
}
I hope this helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2023 05:50 PM
Thank you for this very useful information! I did have to modify the code to work for me so I thought I'd share in case others ran into the same issue. For mine, I had to remove the quotes around the conditions. Hope it helps and thank you again!
//UI Policy Script execute if true
function onCondition(){
if(g_scratchpad.group_member == true && g_scratchpad.group_role == true){
g_form.setDisplay('TeamName', 'true');
}
}