- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2020 08:20 AM
I have been working the past several days and I just cannot get this conditional scheduled reporting to fire properly. Here are the parameters I am looking to fill:
I have a spent the past few days trying to get my conditional script to work and I can get it to work with less than, equal to or not equal to. But, for some reason anything with greater or greater than or equal to isn't functioning properly.
The report that is built and working correctly is looking at the Incident table and is a Speedometer that is going by the Aggregation of Count, The filters within the report is looking at just one Assigned Group and Opened on the Last 45 Minutes.
The building of the conditional schedule report, and where I'm having problems with it firing off correctly, need to not send off if the report is blank. If it isn't blank then it need to check to see if the same parameters are meet plus looking for a count of tickets being at 15 tickets or more. If that is meet then to fire off the Speedometer PNG image.
One of the pieces I have in my code is calling for the Sys ID for the Assignment Group and not the Group's Name so I am not sure if that is one of the concerns or not.
I have utilized the following help guides to troubleshoot different code examples:
https://guide.freecodecamp.org/javascript/comparison-operators/
Build name: Newyork
Build date: 12-17-2019_0856
Build tag: glide-newyork-06-26-2019__patch4-hotfix1-12-16-2019
Solved! Go to Solution.
- Labels:
-
Reporting

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2020 09:21 AM
For date filters in the query the easiest way is to set the same filters on list view and then copy the query in the script in the addEncodedQuery().
This works very smoothly and doing it yourself in the code is way more complex because of different timezone ServiceNow uses (like the system store the time in GMT, users timezone could be anything and also systems timezone could be different).
Best solution I could think for your requirement is as follows-
- Create a report with filters looking something like this-
- Create a Scheduled Email of Report record selecting this record. It is very important to make this report run with appropriate user (things like their access and timezone matters). Otherwise you might not see proper results.
To ensure that select required user (mostly a user from the same assignment group in condition) in the Run as field (If it is not on the form add it and select the user required). - Select "Omit if no records" and that will not trigger the report if there are not required filtered by the report.
- Now coming to condition where you want this to be triggere only if there are more than 14 records.
For this check "Conditional" and you will see a "Condition" field where you can write server side script.
In this script you need to check if there are more than 14 tickets active.
Your script should have the same filters as the report (use encoded query as specified above) and look something like this (please update the filters as required)-
var count = new GlideAggregate('incident'); count.addEncodedQuery("assignment_group=8a4dde73c6112278017a6a4baf547aa7^opened_atRELATIVEGE@minute@ago@45^stateIN1,2,3"); count.addAggregate('COUNT'); count.query(); var incidents = 0; if(count.next()) incidents = count.getAggregate('COUNT'); if (incidents > 14) answer = true; else answer = false;
- Select the assignment group in the Groups field Scheduled Email of Report form.
-
Last but not the least, schedule it as you need.
The result of this configuretion will be a report triggered only if the could is greater than 14.
-Tanaji
Please mark the response correct/helpful if applicable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2020 09:13 AM
So you want to send a notification if there have been more than 14 incidents created in the past 45 minutes and need to condition to properly detect this? Would the job run every 5 minutes to check?
Is it a rolling 45 minutes or 45-minute blocks of time with a reset?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2020 09:21 AM
For date filters in the query the easiest way is to set the same filters on list view and then copy the query in the script in the addEncodedQuery().
This works very smoothly and doing it yourself in the code is way more complex because of different timezone ServiceNow uses (like the system store the time in GMT, users timezone could be anything and also systems timezone could be different).
Best solution I could think for your requirement is as follows-
- Create a report with filters looking something like this-
- Create a Scheduled Email of Report record selecting this record. It is very important to make this report run with appropriate user (things like their access and timezone matters). Otherwise you might not see proper results.
To ensure that select required user (mostly a user from the same assignment group in condition) in the Run as field (If it is not on the form add it and select the user required). - Select "Omit if no records" and that will not trigger the report if there are not required filtered by the report.
- Now coming to condition where you want this to be triggere only if there are more than 14 records.
For this check "Conditional" and you will see a "Condition" field where you can write server side script.
In this script you need to check if there are more than 14 tickets active.
Your script should have the same filters as the report (use encoded query as specified above) and look something like this (please update the filters as required)-
var count = new GlideAggregate('incident'); count.addEncodedQuery("assignment_group=8a4dde73c6112278017a6a4baf547aa7^opened_atRELATIVEGE@minute@ago@45^stateIN1,2,3"); count.addAggregate('COUNT'); count.query(); var incidents = 0; if(count.next()) incidents = count.getAggregate('COUNT'); if (incidents > 14) answer = true; else answer = false;
- Select the assignment group in the Groups field Scheduled Email of Report form.
-
Last but not the least, schedule it as you need.
The result of this configuretion will be a report triggered only if the could is greater than 14.
-Tanaji
Please mark the response correct/helpful if applicable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2020 07:27 AM
The conditional coding worked like a charm!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2023 06:56 AM
I have a similar request. I have to report every-time a new incident was created with specific attributes, the report should contain the incident Information.
i adjusted the script but somehow it never terminated. i checket table view with same querry but there were multiple entries