Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to check the logged in user is a member of a group and group has a role in client side?

Dinesh Kumar1
Giga Contributor

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

2 REPLIES 2

SVimes
Kilo Sage

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!

Sable Vimes - CSA

Matt184
Tera Contributor

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');
     }
}