Hi everyone, is it possible to run script inside t...
# advancedpdf
j
Hi everyone, is it possible to run script inside the advanced pdf template? If yes, how to incorporate this and how to call functions.
k
Copy code
const renderer = render.create();
  renderer.addRecord({ record: invoiceGroup, templateName: 'record' });
  const tempId = 'YOUR_TEMPLATE';

htmlLines = htmlLines.replace(/&/gi, '&');
xmlString = xmlString.replace('{{itemsTable}}', htmlLines);

try {
  const pdfFile = render.xmlToPdf({ xmlString });
  pdfFile.name  = `INVOICE_${invGroupNum}.pdf`;
  return pdfFile;
} catch(e) {
  log.error('error saving pdf', e)
  return null;
}
This is a small portion out of our script. ofcourse you need to add data to the HtmlLines with for instance a saved search or just static data. Then on the template do the following:
<th scope="row">{{Vat}}</th>
<td>{{VAT}}</td>
</tr></table>
{{Headers}} {{itemsTable}}
<table style="width:100%; margin-top: 10px;margin-bottom: 0px; ">
<thead>
</thead>
j
Hi @Kevin Zwemmer thanks, but what I need is a function that is directly called on the Advanced PDF/HTML Templates record, and not via suitescript. Do you know how can this be done?
k
@jhayczee09 I don't think that's possible inside your template... What do you need to do inside your template?
j
I need to call and run a function inside the advanced PDF. Initially, I tried to insert a javascript file inside of it, to call the function, but I always encountered an error.
there's a 3rd party script available for generating a dynamic bank QR code and I want to re-use this and call the functions inside of it via advanced pdf template, so that I don't need to create additional customization just for this.