Team, I am creating an invoice PDF based on an Adv...
# suitescript
a
Team, I am creating an invoice PDF based on an Advanced PDF template, but I have an issue when displaying the subsidiary logo when creating the PDF via suitescript (render.renderAsPdf). When opening it normally from the print button, it works fine. The template has the following to show the logo: <td><#if subsidiary.logo?has_content><div top="-20"><img src="${subsidiary.logo@url}" style="width: 230px; height: 40px;" /></div></#if></td>. Anyone has experienced this issue?
b
you didnt actually explain what the issue was
a
sorry, the logo is not showing up when calling the template from suitescript vs printing the template from the NetSuite Invoice page
it's like the subsidiary object is not populated when calling from suitescript vs regular print
b
use render.transaction if you want all the data to match
otherwise you need to fill in the subsidiary data source yourself
TemplateRenderer are too generic to guess the subsidiary for you
a
okay thanks, let me try the render.transaction
just to know, how could I fill in the subsidiary data source?
b
in this case, probably the same way you filled in the record
a
you mean, in addition to do this: rendererObj.addRecord({ templateName: "record", record: invoiceRecord });
also add the subsididary record?
b
the internalId of the logo used by standard pdf templates matches the internal id of the logo on a record, so you just use TemplateRenderer.addRecord
if it didnt, you would use TemplateRenderer.addCustomDataSource
a
okay, I thought you could only use .addRecord once
but you are suggesting we can use it more than one, adding the invoice record and also the subsididary record, correct?
b
as long as you dont use the same
templateName
a
ok, cool
I will try both options you mentioned, render.transaction and also source both the invoice and subsidiary records, with different templateNames
many thanks, will come back with results
great, the render.transaction works perfect, and it picks up the defined template too
gonna try the other approach now, just to know if it works
also works great by adding a second record
Copy code
// prepare render object with invoice record and subsidiary record
   const rendererObj = render.create();
const invoiceRecord = record.load({
   type: record.Type.INVOICE,
   id: nsInvoiceId,
   isDynamic: false,
});
   rendererObj.addRecord({ templateName: "record", record: invoiceRecord });
   const subsidiaryRecord = record.load({
       type: record.Type.SUBSIDIARY,
       id: invoiceRecord.getValue("subsidiary"),
       isDynamic: false,
   });
   rendererObj.addRecord({ templateName: "subsidiary", record: subsidiaryRecord });
   rendererObj.setTemplateByScriptId({ scriptId: InvoiceAPISettings.InvoiceAdvancedPDFTemplateScriptId });
   // render PDF file and save it to folder
   const invoicePDFile = rendererObj.renderAsPdf();
perfect, thank you so much!