Iterate over loop

Iterate over loop

Hi,

I have the following script setup to create PDF voucher based on the input.Number_Of_E_Vouchers , e.g. if the value is 4, 4 vouchers will be generated, but seem the loop stopped after generating 1 voucher, is there any coding issue with the below script?

Thanks a lot for your suggestion.


  1. //get max voucher
  2. maxVoucher = input.Number_Of_E_Vouchers;
  3. //initialise lists
  4. vList = {0};
  5. vnList = Collection();
  6. //initialise string
  7. vString = "";
  8. //get dates
  9. issueDate = input.Added_Time.tostring("dd-MMM-yyyy");
  10. expiryDate = input.Added_Time.addMonth(3).tostring("dd-MMM-yyyy");
  11. //fetch ac record
  12. acRecord = Add_Customers[ID = input.Add_Customers_Lookup];
  13. custID = acRecord.Customer_ID.tostring();
  14. //iterate over v list
  15. for each index vl in vList
  16. {
  17. //fetch ts record
  18. tsRecord = Templates[Type = "Customers" && For_field = "Actual Voucher Template" && Status == "Active"];
  19. //check if
  20. if(vl < maxVoucher)
  21. {
  22. //creates voucher number
  23. vn = input.ID + "-" + vl;
  24. vqrc = "<img src='https://chart.googleapis.com/chart?chl=" + vn + "&chs=100x100&cht=qr&chld=H|0'/>";
  25. //add vn to list
  26. vnList.insert(vn);
  27. //creates vt string
  28. vtString = tsRecord.Message;
  29. //replace merge fields
  30. vtString = vtString.replaceAll("${Name}",input.Add_Customers_Lookup.Name,true);
  31. vtString = vtString.replaceAll("${Customer_ID}",custID,true);
  32. vtString = vtString.replaceAll("${voucherType}","Entitles the bearer to 1 Lesson",true);
  33. vtString = vtString.replaceAll("${expiryDate}",expiryDate,true);
  34. vtString = vtString.replaceAll("${issueDate}",issueDate,true);
  35. vtString = vtString.replaceAll("${voucherQRcode}",vqrc,true);
  36. vtString = vtString.replaceAll("${voucherNum}",vn,true);
  37. vList.add(vl + 1);
  38. //check if
  39. if(vl = maxVoucher - 1)
  40. {
  41. vString = vString + "<div>" + vtString + "</div>";
  42. }
  43. else
  44. {
  45. vString = vString + "<div>" + vtString + "</div><p style='page-break-after: always !important;'>&nbsp;</p>";
  46. }
  47. }
  48. }
  49. input.voucherNumberList = vnList;
  50. input.voucherDetail = vString;
  51. //fetch te record
  52. teRecord = Templates[Type = "Customers" && For_field = "Voucher Email" && Status == "Active"];
  53. //check if
  54. if(teRecord.count() > 0)
  55. {
  56. //fetch subject
  57. subjectLine = teRecord.Subject_field;
  58. //fetch message
  59. messageBody = teRecord.Message;
  60. //replace merge fields
  61. messageBody = messageBody.replaceAll("${Name}",acRecord.Name,true);
  62. messageBody = messageBody.replaceAll("${Customer_ID}",custID,true);
  63. messageBody = messageBody.replaceAll("${voucherType}","Entitles the bearer to 1 Lessons",true);
  64. messageBody = messageBody.replaceAll("${expiryDate}",expiryDate,true);
  65. vtString = vtString.replaceAll("${issueDate}",issueDate,true);
  66. sendTo = "test@test.com"
  67. //send mail
  68. sendmail
  69. [
  70. from :zoho.adminuserid
  71. to :"test@test.com"
  72. subject :subjectLine
  73. message :messageBody
  74. Attachments :template:E_Voucher_Actual_Template as PDF
  75. ]
  76. }