- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2022 12:11 PM
Hello,
I am trying to get a report to send every hour if there are 5 or more records in it. I have tried several different configurations of this, but regardless of what condition script I try it always sends regardless. See screenshots for different attempts at scripts.
Any assistance with what I may be doing wrong is appreciated.
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2023 10:21 PM
Did some testing in San Diego Patch 8
- In the Scheduled Report
- ensure the subject field has a value
- ensure the Run As user has necessary roles to read the table / records
- Set the system property glide.security.sandbox_no_logging to false (at least in your sub-prod environment) so you can see logging statements
- Confirm the recipients have notifications enabled
The following conditional script is working
var conditionCheck = false;
var encodedQuery = 'active=true^assignment_group=0c43a02f6f9875009efada55eb3ee40e';
var ga_inc = new GlideAggregate('incident');
var recordCount = 0;
ga_inc.addEncodedQuery(encodedQuery);
ga_inc.addAggregate('COUNT');
ga_inc.query();
if (ga_inc.next()){
recordCount = ga_inc.getAggregate('COUNT');
if (recordCount > 3) {
conditionCheck = true;
}
}
gs.log(recordCount);
gs.log(conditionCheck);
answer = conditionCheck;
I tested to ensure it ran when count of records was greater than 3 and did not run when count of records was less than the threshold
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2022 01:02 PM
Hey Josh,
first of all, please note that Conditions scripts are not evaluated when testing scheduled reports using the Execute Now button.
If this is not the cause of your problem, please note that you should not use getRowCount() because this method creates a heavy load on the system. Instead, use GlideAggregate.
Which script you have to use depends on your current release. If your instance is at Tokyo or Rome the first script with "answer" is the correct one: See here https://developer.servicenow.com/dev.do#!/learn/learning-plans/tokyo/servicenow_administrator/app_st...
Feel free to answer if the script is still not working after changing it to GlideAggregate and not testing it with the "Execute now" button.
Best regards
Oli
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2022 03:03 PM
Hi Oli,
Thanks for your response. I updated the script to GlideAggregate. Unfortunately it is still sending on each interval.
Update Screenshot below.
Thank you again for your assistance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2022 12:31 AM
Hey again,
I tried it myself in a background script and it works fine for me.
So just to double check: Are you sure that your query is correct and there are more than 4 results?
Best regards
Oli
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2022 08:30 AM
Thanks for your response, and yes I am sure my query is correct. When I pull the total number of records that match the query, there are only 3, so that is the source of my confusion.