- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2022 02:57 AM
Hello All ,
I have a requirement where I need to write a schedule job which will fetch up all the records which are deactivated in the last 7 days , means active = false .
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2022 03:07 AM - edited 11-25-2022 03:10 AM
Try this.
var grSysUser = new GlideRecord('sys_user');
grSysUser.addEncodedQuery("active=false^sys_updated_onRELATIVEGT@dayofweek@ago@7");
grSysUser.query();
while (grSysUser.next()) {
//do something.
}
You can use Updated On field or Last Login field accordingly.
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2022 03:07 AM - edited 11-25-2022 03:10 AM
Try this.
var grSysUser = new GlideRecord('sys_user');
grSysUser.addEncodedQuery("active=false^sys_updated_onRELATIVEGT@dayofweek@ago@7");
grSysUser.query();
while (grSysUser.next()) {
//do something.
}
You can use Updated On field or Last Login field accordingly.
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2022 03:15 AM
Hello,
The normal script would be as below:-
var gr=new GlideRecord('sys_user');
gr.addEncodedQuery('active=false^sys_updated_onRELATIVEGT@dayofweek@ago@7');
gr,query();
while(gr.next);
{
var arr=gr.user_name;
}
Now this is actually tricky because the last updated date does not guarantee the date on which it was made inactive. Do you have the audit enabled on User table if yes then it would be easier to get the exact time when the field was made inactive.
Or you can create a metric definition on sys_user table for active field whenever the field is made inactive the record would be captured in metric_definition and then you can get the list from metric_definition.
Please mark my answer as correct based on Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2022 12:18 AM
Hello,
If my answer helped you can you also mark it as correct.
Thanks.