- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2024 06:21 AM
I am trying to delete the group members and set the group values empty with below workflow run script
but not working
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2024 06:24 AM
what does this variable u_existing_group hold?
Is it a group sysId?
If yes then update as this
var grpId = current.variables.u_existing_group;
// set the group fileds empty
var gr = new GlideRecord('sys_user_group');
gr.addQuery('sys_id',grpId);
gr.query();
if(gr.next()){
gr.parent = '';
gr.default_assignee = '';
gr.type = '';
gr.active = 'false';
gr.update();
}
//Delete group members
var grRemoveMember = new GlideRecord('sys_user_grmember');
grRemoveMember.addQuery('group', grpId);
grRemoveMember.query();
while(grRemoveMember.next()){
grRemoveMember.deleteRecord();
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2024 07:26 AM
Something similar
var groupRoleRec = new GlideRecord('sys_group_has_role');
groupRoleRec.addQuery('group', grpId);
groupRoleRec.query();
while(groupRoleRec.next()){
groupRoleRec.deleteRecord();
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2024 07:26 AM
Something similar
var groupRoleRec = new GlideRecord('sys_group_has_role');
groupRoleRec.addQuery('group', grpId);
groupRoleRec.query();
while(groupRoleRec.next()){
groupRoleRec.deleteRecord();
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2024 06:26 AM
grRemoveMember.addQuery("user", 'IN', grpId);
This condition looks incorrect as you are adding a condition for the user field and passing the sys_id of the group. Due to this the query will fail and deletion will never take place.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2024 06:46 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2024 08:30 AM
@Brahmi Pandla I didn't share the script, I just shared the reason why the script was not working.