Scheduled report execution ignoring conditions.

Josh Evans
Tera Contributor

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!

 

script screenshot 1.PNG

script screenshot 2.PNG

1 ACCEPTED SOLUTION

stevemac
Tera Guru

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 

View solution in original post

15 REPLIES 15

Oliver Stammler
Giga Guru

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

Hi Oli,

 

Thanks for your response. I updated the script to GlideAggregate. Unfortunately it is still sending on each interval. 

Update Screenshot below.

 

JoshEvans_0-1671059004734.png

Thank you again for your assistance.

Hey again,

I tried it myself in a background script and it works fine for me.

OliverStammler_0-1671092861247.png


So just to double check: Are you sure that your query is correct and there are more than 4 results? 

Best regards

Oli

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.