Need to remove multiple inactive users from groups
This content was last updated in 2018. It may still be useful, but could contain outdated information. Please confirm its accuracy before relying on it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2018 03:43 AM
Hi All,
I have a requirement to remove inactive users who are all more than 15 days from today from the group member table by using scheduled job. I have written a script for this. But whenever I execute it, It removes only few inactive users from groups..Assume I have 700 Inactive Grp members, first time - 692, second time - 678..Like that, It is working...But I want it in a single shot. Below is My script., Do we have any functionality ? Because I cannot modify the 'slice' each time.
Please post your suggestions.
Thanks In Advance
gs.log("********Removing Inactive Users from Groups********");
var nowdate = gs.now();
var gr=new GlideRecord("sys_user");
gr.addQuery('active', false);
gr.query();
gs.log('RemovingInactive users: ' + gr.getRowCount());
while(gr.next()){
var result = gs.dateDiff(nowdate, gr.u_term_date, false);
var res = result.slice(1,4);
if(res > 15){
//gs.log('Day :' + res);
var grmember = new GlideRecord('sys_user_grmember');
grmember.addQuery('user', gr.sys_id);
grmember.query();
while(grmember.next()){
grmember.deleteMultiple();
grmember.update();
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2018 05:08 AM

I just commented update() and tried but still no luck. I am getting the days format which is shown in the above image. So I have used Slice(1,4) to neglect '-' from the format.