Fix script to add 3 user in a field

Deo Christian V
Tera Contributor

DeoChristianV_0-1745542670209.png

Need a fix script to add 3 users in Co-managers field in a group

11 REPLIES 11

Kieran Anson
Kilo Patron

Hi Deo,

Can you provide more context? It'll be a simple GlideRecord you'll need to do. Assuming this a glide_list field, and you know the 3 users to populate. 

var gr = new GlideRecord('sys_user_group');
gr.addEncodedQuery('nameSTARTSWITHBilling team');
gr.setLimit(1);
gr.query();
 
if(gr.next()){
gr.u_co_manager = '556d03520f064a0035fde478b1050e0d';
gr.update();
}

I need 3 users on Co-managers. Script above only caters one user

If the field is a glide_list, provide it with a string of comma separated sys_ids

*sys_id1,sys_id2,sys_id3"

@Deo Christian V 

that field can hold 3 users only if it's a glide list field

If yes then simply follow what @Kieran Anson mentioned

something like this

var gr = new GlideRecord('sys_user_group');
gr.addEncodedQuery('nameSTARTSWITHBilling team');
gr.setLimit(1);
gr.query();
 
if(gr.next()){
gr.u_co_manager = '556d03520f064a0035fde478b1050e0d,sysId2,sysId3'; // give other 2 user sysIds here
gr.update();
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader