- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2022 12:39 AM
Hello Everyone,
I need to get the incidents which are created from past 3 days using script. can anyone help me in achieving this.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2022 01:42 AM
hi @Supriya KM ,
Please use below script to get the count of incidents which are created on past 3 days.
var ga = new GlideAggregate("incident");
ga.addEncodedQuery('sys_created_onRELATIVEGT@dayofweek@ago@03'); //get incidnets created on last 3days
ga.addAggregate("COUNT");
ga.query();
while (ga.next()) {
gs.info("Total Count is " +ga.getAggregate("COUNT")); //get the count
}
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2022 12:48 AM
Hi @Supriya KM ,
Try Below script using Bachground script or fix script:
var count = '';
var gr = new GlideRecord('incident');
gr.addQuery('caller_id=681ccaf9c0a8016400b98a06818d57c7^sys_created_onRELATIVEGE@dayofweek@ago@3'); // sys_id of joe employeeuser
gr.query();
//gs.print('Count'+gr.getRowCount());
while(gr.next()){
count++;
}
gs.print('Count'+gr.getRowCount());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2022 01:08 AM
Hello,
Could you please try below script -
var gd = new GlideRecord('incident');
gd.addEncodedQuery('sys_created_onRELATIVEGE@dayofweek@ago@3');
gd.query();
while(gd.next()) {
//var num = gd.number;
}
gs.print('name : '+gd.getRowCount());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2022 01:42 AM
hi @Supriya KM ,
Please use below script to get the count of incidents which are created on past 3 days.
var ga = new GlideAggregate("incident");
ga.addEncodedQuery('sys_created_onRELATIVEGT@dayofweek@ago@03'); //get incidnets created on last 3days
ga.addAggregate("COUNT");
ga.query();
while (ga.next()) {
gs.info("Total Count is " +ga.getAggregate("COUNT")); //get the count
}
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2022 06:20 AM
Thank you Pavan, it worked!!!