Tag a role to an Assignment Group

sachinhs
Tera Contributor

Folks,

Need your help on how to add/append a Role to an Assignment group via script.

On a custom module, user will select a Role (Choice) and Group (Reference), once saved I want to add that role into the group, so that everyone under that Group will inherit the Role.

 

Kindly suggest.

8 REPLIES 8

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @sachinhs 

 

Why don't you use the Flow designer and catalogue item for the same? Create a catalogue item ask the user about role and group and then in flow in action update the record. 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Have to agree with @Dr Atul G- LNG here.  A lot less can go wrong if you use Flow Designer.
Assuming the user is filling out a form on the Catalog....

Trigger:  Catalog Item
Flow
1 - Get Variables 
2 - Lookup record (sys_group_has_role) where...
- role is same as role variable
- group is same as group variable
3 - If 2 returns something
4 notify user group already has that role
5 ELSE
6 Create Record (sys_group_has_role)
--- role = role variable

--- group = group variable

Anand Kumar P
Giga Patron
Giga Patron

Hi @sachinhs ,

 

You can create after insert business rule on custom table with below script.

 

var role = new GlideRecord('sys_group_has_role');

 

role.initialize();

 

role.group = current.groupfiled_backendname;

 

role.role = current.rolefiled_backendname;

 

role.insert();

If my response helped, please mark it as the accepted solution and give a thumbs up👍.
Thanks,
Anand

Thank you Anand for the response.

If i can seek some more help, below is my form from a custom application.

sachinhs_0-1735388555862.png

Here Role is "Choice" and Assignment Group is "Reference". To retrieve a Choice field's value from BusinessRule, should we use Client script and AJAX & then trigger BusinessRule?

Kindly suggest..