Catalog item run script

Mustafeez
Tera Contributor

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.

3 REPLIES 3

_Gaurav
Kilo Sage

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!

SN_Learn
Kilo Patron
Kilo Patron

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();

 

 

SN_Learn_0-1707894529809.png

 

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.

Service_RNow
Mega Sage

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