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

Adding another point,  current object will not work. 

Thank you Harshvardhan! With that, I created scheduled script execution that triggers the scheduled report instead.  The report has the PDF file type which I need.  Thanks again!

 

robebe07
Tera Contributor

Would you mind providing an example of the scheduled script? I have a similar problem and would appreciate any guidance you can provide. Thank you

Sharing what I recall from this topic.
1. Scheduled report
2. Scheduled script
new global.ScriptIncludeNameHere().notifyAssignmentGroups('Report name');


Below is the script include:

notifyAssignmentGroups: function (schdRptName) {

var grpList=[];
var rec = new GlideRecord('sysauto_report');
rec.get('name', schdRptName);

var tsk = new GlideRecord(rec.report.table);
tsk.addEncodedQuery(rec.report.filter);
tsk.query();

while (tsk.next()) {
var grp=tsk.getValue('assignment_group');
if (this._isAlreadyAdded(grp, grpList))
continue;
grpList.push(grp);
}
//gs.log(grpList);
rec.setValue('group_list', grpList);
rec.update();

SncTriggerSynchronizer.executeNow(rec);
}

 

Hope this helps!