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.
- //get max voucher
- maxVoucher = input.Number_Of_E_Vouchers;
- //initialise lists
- vList = {0};
- vnList = Collection();
- //initialise string
- vString = "";
- //get dates
- issueDate = input.Added_Time.tostring("dd-MMM-yyyy");
- expiryDate = input.Added_Time.addMonth(3).tostring("dd-MMM-yyyy");
- //fetch ac record
- acRecord = Add_Customers[ID = input.Add_Customers_Lookup];
- custID = acRecord.Customer_ID.tostring();
- //iterate over v list
- for each index vl in vList
- {
- //fetch ts record
- tsRecord = Templates[Type = "Customers" && For_field = "Actual Voucher Template" && Status == "Active"];
- //check if
- if(vl < maxVoucher)
- {
- //creates voucher number
- vn = input.ID + "-" + vl;
- vqrc = "<img src='https://chart.googleapis.com/chart?chl=" + vn + "&chs=100x100&cht=qr&chld=H|0'/>";
- //add vn to list
- vnList.insert(vn);
- //creates vt string
- vtString = tsRecord.Message;
- //replace merge fields
- vtString = vtString.replaceAll("${Name}",input.Add_Customers_Lookup.Name,true);
- vtString = vtString.replaceAll("${Customer_ID}",custID,true);
- vtString = vtString.replaceAll("${voucherType}","Entitles the bearer to 1 Lesson",true);
- vtString = vtString.replaceAll("${expiryDate}",expiryDate,true);
- vtString = vtString.replaceAll("${issueDate}",issueDate,true);
- vtString = vtString.replaceAll("${voucherQRcode}",vqrc,true);
- vtString = vtString.replaceAll("${voucherNum}",vn,true);
- vList.add(vl + 1);
- //check if
- if(vl = maxVoucher - 1)
- {
- vString = vString + "<div>" + vtString + "</div>";
- }
- else
- {
- vString = vString + "<div>" + vtString + "</div><p style='page-break-after: always !important;'> </p>";
- }
- }
- }
- input.voucherNumberList = vnList;
- input.voucherDetail = vString;
- //fetch te record
- teRecord = Templates[Type = "Customers" && For_field = "Voucher Email" && Status == "Active"];
- //check if
- if(teRecord.count() > 0)
- {
- //fetch subject
- subjectLine = teRecord.Subject_field;
- //fetch message
- messageBody = teRecord.Message;
- //replace merge fields
- messageBody = messageBody.replaceAll("${Name}",acRecord.Name,true);
- messageBody = messageBody.replaceAll("${Customer_ID}",custID,true);
- messageBody = messageBody.replaceAll("${voucherType}","Entitles the bearer to 1 Lessons",true);
- messageBody = messageBody.replaceAll("${expiryDate}",expiryDate,true);
- vtString = vtString.replaceAll("${issueDate}",issueDate,true);
- sendTo = "test@test.com"
- //send mail
- sendmail
- [
- from :zoho.adminuserid
- to :"test@test.com"
- subject :subjectLine
- message :messageBody
- Attachments :template:E_Voucher_Actual_Template as PDF
- ]
- }