Catalog item run script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2024 01:20 PM
Hello Everyone,
In a catalog item I have a user field and a group field, while i select the user name and group and submit the catalog form user should be added to the respective group how can I solve either run script or script include?
I will hear from you soon please reply ASAP.
Thanks,
Mustafeez.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2024 10:55 PM - edited 02-13-2024 10:58 PM
Hi @Mustafeez
This can be done through the run script.
var grmember = new GlideRecord('sys_user_grmember');
grmember.initialize();
grmember.user = current.variables.u_user;
grmember.group = current.variables.u_group;
grmember.insert();
Thanks!
Please mark this as helpful if this resolves your query.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2024 11:09 PM - edited 02-13-2024 11:10 PM
Hi @Mustafeez ,
You can achieve it by adding an activity called ' run script' in the workflow as below:
//update the backend names in the below script as per your field's backend name
var getUser = current.variables.requested_for; //get the sysID of selected user
var getGrp = current.variables.group; //sysID of selected group
var addUser = new GlideRecord('sys_user_grmember');
addUser.initialize();
addUser.setValue('user', getUser);
addUser.setValue('group', getGrp);
addUser.insert();
Please le me know your views and Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Mark this as Helpful / Accept the Solution if this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2024 11:12 PM
Hi @Mustafeez
Go with Run Script try to below code :
var rec = new GlideRecord('sys_user');
rec.addActiveQuery();
rec.query();
while (rec.next())
{
var rec1 = new GlideRecord('sys_user_grmember');
rec1.addQuery('user' , rec.sys_id);
rec1.addQuery('group' , '9005cb35db91c700c1fa7d9ebf96193a'); // put the sys_id of "GroupA" here
rec1.query();
if(!rec1.next())
{
rec1.initialize();
rec1.user = rec.sys_id;
rec1.group = '9005cb35db91c700c1fa7d9ebf96193a'; // put the sys_id of "GroupA" here
rec1.insert();
gs.log("Group A record inserted");
}
}
Here instead of hardcoding the group sys_id you can get it from property by defining in Properties.
Please mark as helpful or correct based on impact