Scheduled Email of Report throwing error: Illegal use of while loop in sandbox scope: org.mozilla.javascript.Parser.whileLoop

Babeth1
Kilo Explorer

Hello, I'm not sure what I am missing here.  Executing Scheduled Email of Report with below condition script.  If I hardcode the grList value, it is working.  This schedule is

var answer=false;

var scheduleReport = new GlideRecord('sysauto_report');
scheduleReport.get(current.sys_id); //Sys ID of your schedule Report

var tablename = scheduleReport.report.table;
var query = scheduleReport.report.filter;

var grpList='';
var gr=new GlideRecord(tablename);
gr.addEncodedQuery(query);
gr.query();
while (gr.next()) {
var grp=gr.getValue('assignment_group');
grpList += ',' + grp;

}
//var grList='679434f053231300e321ddeeff7b12d8,8a5055c9c61122780043563ef53438e3';

if (grList.length>0) {
current.group_list=grList;
current.update();
anwswer=true;
}

Thanks, Babeth

 

1 ACCEPTED SOLUTION
9 REPLIES 9

Harsh Vardhan
Giga Patron

variable answer is not correct , another typo with grpList variable also use grpList as an array to store the value. 

 

Try now

 

var answer=false;

var scheduleReport = new GlideRecord('sysauto_report');
scheduleReport.get(current.sys_id); //Sys ID of your schedule Report

var tablename = scheduleReport.report.table;
var query = scheduleReport.report.filter;

var grpList=[];
var gr=new GlideRecord(tablename);
gr.addEncodedQuery(query);
gr.query();
while (gr.next()) {
grpList.push(gr.getValue('assignment_group'));

}


if (grpList.length>0) {
current.group_list=grpList;
current.update(); 
answer=true;
}

 

Note: If you are using this script in business rule then don't use current.update()

Copy-pasted the code but no email generated, no error thrown as well.  The conditional is also checked.

So this time you are not getting "throwing error: Illegal use of while loop in sandbox scope: org.mozilla.javascript.Parser.whileLoop"

 

May i know, how are you testing it?  if you are checking the condition then no need to use current.update(), 

Sorry, it has that error.  I test by clicking the button Execute Now.