Validate logged in User is member of Specific Group

Vamshi Krishna2
Tera Contributor

Hi I have a requirement if logged in user is member of specific group then I have a choice variable in catalog item with 2 options for eg: XYZ, and ABC . if the User is member of group A then I need to set a XYZ as a Default value or if user is member of Group B then I need to set the Value to ABC. How can I do this can anyone help?

2 REPLIES 2

AnubhavRitolia
Mega Sage

Hi @Vamshi Krishna2 

 

You can use gs.isMemberOf('group_name') function to check that the logged is user is member of special group or not.

 

Write Script include where you check if user is member of Group A then return XYZ and if member of Group B then return ABC.

 

Now in default value of your choice variable call above script include as below:

 

javascript: new ScriptIncludeaName(). functionName();

 

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

kamlesh kjmar
Mega Sage

Hi @Vamshi Krishna2 ,

 

Put a one liner script in your defalt value and it should work for you. Replace order support with your group name and xyz and abc with your option value:

 

javascript:gs.getUser().isMemberOf( "Order Support")  ?"xyz":"abc"

 

 

kamleshkjmar_0-1667532446204.png

 

Above script says if logged in user is member of Order support group then default option will be xyz if not then default option will be abc

 

I hope this help.

 

Please mark this helpful if this helps and Accept the solution if this solves your issue.

 

Regards,

Kamlesh