- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2018 08:28 AM
Hello everyone,
I am trying to remove all records from the grpmember table that shows the group empty. I am running a background script but only deletes one record and script exits.
Here is what I have:
gs.log("Begin removeBlankRecords","clean up group members");
VAR GR = new GlideRecord('sys_user_grmember');
gr.addEncodedQuery('group.nameISEMPTY^ORuser.nameISEMPTY');
gr.query();
var count = 0;
while(gr.next()){
if(gr.deleteRecord()){
count = count + 1;
}
else{ gs.log("Could not delete sys_user_grmember record: sys_id = "+gr.sys_id,"clean up group members");
}
gs.log("Total blank records deleted: "+count, "clean up group members");
}
Will greatly appreciate any assistance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2018 08:32 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2018 09:30 AM
Hello there,
I tried the change to the script and still deletes only one record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2018 09:56 AM
can you try this?
var count = 0;
var gr = new GlideRecord('sys_user_grmember');
gr.addEncodedQuery('group.nameISEMPTY^ORuser.nameISEMPTY');
gr.query();
while(gr.next()){
gr.deletemultiple();
count++;
}
gs.print("Total blank records deleted: "+count);
