Some PDIs are currently unavailable, and PDI actions are paused. View the latest updates here. Read More

Scheduled reports advanced conditions

mrsellicat
Tera Contributor

We have a handful of scheduled reports that have advanced conditions.  These conditions have stopped working due to the crack down on sandbox scripts (KB2944435).

 

We have followed the advice and moved the code to a script include. The function works fine when called from a background script, a business rule and even a UI Action.  I have been using script debugger to see when it is triggered and what the variables are. However, it won't trigger from the condition on the scheduled report.

The code we are using is to check if another report (P) has data in it.  We only want report (C) to be generated if (P) has data in it. The script include function is as follows:

var My_Report_helper = Class.create();
My_Report_helper.prototype = {
initialize: function() {},

// Check report has data
checkReportData: function(reportSysId) {
var answer = false;
var grReport = new GlideRecord('sys_report');
if (grReport.get(reportSysId)) {
var gr = new GlideRecord(grReport.table);
gr.addEncodedQuery(grReport.filter);
gr.query();
answer = gr.hasNext(); // Only send if main report has data
}
return answer;
},

type: 'My_Report_helper'

};

 

Calling
new My_Report_helper().checkReportData('1234356789');
in a background script works but it doesn't work in the condition of the scheduled report.  It works in background script with Execute in sandbox? checked and unchecked.

I have also tried the following in the scheduled report condition:
My_Report_helper().checkReportData('1234356789');
javascript:new My_Report_helper().checkReportData('1234356789');

But it doesn't seem to trigger the function either.  I have tried toggling the Sandbox enabled and Client callable flags on the script include.  The script include is in Global and the Accessible from is set to all application scopes. 

 

3 REPLIES 3

abbasshaik4
Tera Sage

Hello @mrsellicat,

 

Please refer to the link below:
Exploring Advance Reporting Conditions using Scrip... - ServiceNow Community

 

If it is helpful, please mark it as helpful and accept the correct solution by referring to this solution in the future it will be helpful to them.

 

Thanks & Regards,

Abbas Shaik

Thank you @abbasshaik4 , that was an interesting read, I didn't know we could do that with report conditions.

 

My problem is with the condition on a scheduled report.  I need to call the script include function from the condition field on sysauto_report.

 

Best regards, Cath

Ankur Bawiskar
Tera Patron

@mrsellicat 

let them auto-trigger based on your schedule like daily etc and then verify if the conditions are evaluated or not

If you are trying to click Execute Now then I think the script condition doesn't evaluate

💡 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