Script to add users to a group

Aishwarya Selv1
Tera Contributor

I wanted to write a script where we get each user from sys_user table and check if they have a manager, if yes, then add the manager to a group.

 

Can someone help me with this.

2 REPLIES 2

Samaksh Wani
Giga Sage
Giga Sage

Hello @Aishwarya Selv1 

 

 

var gr = new GlideRecord('sys_user');
gr.addQuery();

while(gr.next()){
if(gr.manager !=""){
// adding logic into group
}
}

 

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it Helpful.

 

Regards,

Samaksh

Community Alums
Not applicable

Hello @Aishwarya Selv1 ,

 

Please refer to this : https://www.servicenow.com/community/now-platform-forum/query-all-managers-add-to-group/m-p/1134486

 

@Aishwarya Selv1, Please mark my answer as "Accept as Solution" and "Helpfuls." If it works for you.

 

Thank you!