EVAL block not working in Email Template

Posted by lCira9 on 15-May-2014 02:56

Hi,

My EVAL block is completely working in the Test EVAL[ ]. However, when I put it in an Email Template there is an error: 

ERROR: Error missing ) after for-loop control (line #4) in formula: var rbv_api = new Packages.com.rb.core.services.api.ServerSideAPI(1, 5790); function wrapper() { var email = rbv_api.selectQuery("SELECT email, id FROM collector",20000); var user = null; for (var i = 0; i < email.length; i++) { if ( "bobsemail@gmail.com" == email[i][0]) { user = email[i][1]; }...  

This error also occurs when you remove the quotes in "bobsemail@gmail.com" when in Test EVAL[ ]. But in the email template, even if there are quotes, the error occurs.

This the whole eval block: 

var email = rbv_api.selectQuery("SELECT email, id FROM collector",20000);
var user = null;
for (var i = 0; i < email.length; i++) {
if ( "{!#CURR_USER.email#text}" == email[i][0])
{
user = email[i][1];
}
}
var statementList = rbv_api.selectQuery("SELECT statement_collector, id FROM statement",20000);
var index = 0;
var total = 0;
for(var j = 0 ; j < statementList.length ; j++) {
if(statementList[j][0] != null && statementList[j][0] == user) {
var currDate = rbv_api.formatDate(new Date(), "yyyy-MM-dd");
var paidList = rbv_api.selectQuery("SELECT amount_paid, createdAt, R8427 FROM pr_receipt", 20000);

for(var i = 0; i < paidList.length; i++) {
var date = rbv_api.formatDate(paidList[i][1], "yyyy-MM-dd");
if(currDate == date && paidList[i][2] == statementList[j][1]) total += +paidList[i][0];
}
}
}
return total;

Thanks.

All Replies

Posted by Laurent on 20-May-2014 08:48

Could you try to simplify the code to a minimum? When I try a simple block eval in my email template I do not get any error.

     #EVAL[a = "test"; if ("{!#CURR_USER.email#text}" == a) { 42; } else {32;} ]

This thread is closed