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

Hey Josh,

in this case the last check we can do is to check if the script is running and if we really reach the "else" part. 
So I would suggest to add a log in line 1 to check if the script is starting and another log within the if/else to see where we end. 

In addition I would remove the function and just execute the script.
So please remove line 1 and line 18

Best regards
Oli

Thank you for your continued assistance. Unfortunately the problem is persisting. It ran properly for me as a background script as well, but still for whatever reason all the issues I laid out before continue. In addition to that, it isn't logging anything when running from the scheduled execution. Nothing at the beginning or in the middle. This log is consistently repeating though.

JoshEvans_0-1671132049952.png

 

@Josh Evans I think you wanted to check if the 5 or more records created in that hour. If yes then add one more query to the GlideAggregate that is "Created on last hour".

Without "Created on last hour", its getting more than 5 records all the time, that's why report is getting sent each time.

 

Please check.

 

Please mark as correct answer if this solves your issue.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

Hello,

 

And no I just want to check the number of records that match the query conditions. At present in the instance there are only 3 total records on that table that are pulled by that query.

 

Thanks for your response.

@Josh Evans Got it. Please update the script as below

 

//Define function first

function getNumberOfRecord(){

//YOUR GLIDERECORD QUERY HERE WITH RETURN TRUE OR FALSE AS YOU ARE DOING

}

 

//Them call function

getNumberOfRecord();

 

Please mark as correct answer if this solves your issue.

 

 

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023