Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

Sheduled report conditional script NEVER gets evaluated

Kingstan M
Mega Sage

Hi SNCommunity Team,

Greetings.

 

Sheduled report conditional script NEVER gets evaluated

 

Business Requirement

The report should run on the first business day of every month.

Expected behaviour:

  • If the 1st of the month falls on a weekday (Monday-Friday), run on the 1st.
  • If the 1st falls on a Saturday, run on Monday the 3rd.
  • If the 1st falls on a Sunday, run on Monday the 2nd.

I tried using script include or code on the cond., block. This never gets evaulated.

 

I created the following Script Include:

var MyReportCondition = Class.create();

MyReportCondition.prototype = {

shouldRun: function() {

var gd = new GlideDate();

 

return (

gd.getDayOfMonthLocalTime() == '1' &&

gd.getDayOfWeekLocalTime() >= 1 &&

gd.getDayOfWeekLocalTime() <= 5

);

},

 

type: 'MyReportCondition'

};

Scheduled Report Condition:

answer = new MyReportCondition().shouldRun();

 

I also observed this,

 

KittyScript validation errors

 

During testing, I attempted to add logging directly into the condition script, for example:

gs.info('test');

answer = false;

or

gs.error('test');

answer = false;

This resulted in KittyScript-related parsing/validation errors such as:

KittyScript validation failed

Expected end of expression but found 'answer'

Expected end of expression but found 'gs'

From the stack trace/logs, it appeared the condition was being evaluated via:

MailReportJob.shouldExecuteScriptConditionSandboxed()

KittyScriptEvaluator

GlideScopedEvaluator.evaluateCondition()

This made me wonder whether the scheduled report condition is being processed through a sandboxed evaluator that has restrictions on supported syntax.

 

But when i just give true or false in the cond., block then the report send or no-send.

 

I am quite not sure why this behaviour. Hence seeking expert's advise, thanks & kind regards.

 

1 REPLY 1

Ankur Bawiskar
Tera Patron

@Kingstan M 

I read somewhere if you execute the Scheduled Report manually via "Execute Now" the condition script doesn't run

that could be one of the reason

Did you try with simple script?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader