Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

Remove users from all itil groups

Devansh1
Tera Contributor

Hii all,
I have to remove some specified users from the all itil groups .Also please note for each user which group they are part of before we remove them from groups, so that in future if needed we can add them back in those groups.

Please tell the approach to achieve this.

Thanks..

1 REPLY 1

Not applicable

Hi @Devansh1 ,

I tried your problem in my PDI and I got the solution 

Please use below script

var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group', '8a4dde73c6112278017a6a4baf547aa7'); // Group sys_id you can change as per your requirments
gr.query();
gs.print(gr.getRowCount());
while(gr.next()){
	gs.print('gr.user = ' + gr.user)
	if(gr.user == '22826bf03710200044e0bfc8bcbe5dec'){ // User Sys_id you can change as per your requirments
		gs.print('Inside if ');
		gr.deleteRecord();
	}
}

 

Result : 

SarthakKashya2_0-1714116680876.png

When I run the above script 

 

SarthakKashya2_1-1714116730609.png

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak