Here we can pass an object to render method to print the PDF .
// Load the item fulfillment record
let itemFulfillmentRecord = record.load({
type: ‘itemfulfillment’,
id: recordid,//internali id of the record
isDynamic: true,
});
// Load the Sales Order record
let salesOrderRecord = record.load({
type: ‘salesorder’,
id: salesOrderId,//internal id of the record
isDynamic: true,
});
log.debug(“salesOrderRecord”, salesOrderRecord);
let renderer = render.create();
renderer.setTemplateById(149);//internal id the advanced pdf template
renderer.addRecord(‘record’, itemFulfillmentRecord);
// Convert the cleaned Sales Order data to JSON
let jsonSalesOrderData = JSON.stringify(salesOrderRecord);
// Pass the cleaned Sales Order data to the renderer
renderer.addCustomDataSource({
format: render.DataSource.JSON,
alias: ‘salesOrder’,
data: jsonSalesOrderData,
});
// Pass the billing address lines individually to the renderer
let addressLinesBill = cleanedSalesOrderData[‘billingaddress_key’];
// Pass the billing address lines as an array to the renderer
renderer.addCustomDataSource({
format: render.DataSource.OBJECT,
alias: ‘billing_address_lines’,
data: addressLinesBill,//object of address book values
});
// Render the PDF
let pdfFile = renderer.renderAsPdf();
// Send the PDF as a response
scriptContext.response.writeFile({
file: pdfFile,
isInline: true
});
In the pdf template use the alias name to get the values as mentioned as below.
<#list billing_address_lines as key>
<#if key.billing_address_addr?has_content >${key.billing_address_addr}<br/></#if>
<#if key.billing_address_line1?has_content >${key.billing_address_line1}<br/></#if>
<#if key.billing_address_line2?has_content >${key.billing_address_line2}<br/></#if>
<#if key.billing_address_city?has_content > ${key.billing_address_city} </#if>
<#if key.billing_address_state?has_content >${key.billing_address_state} </#if>
<#if key.billing_address_zip?has_content >${key.billing_address_zip}<br/></#if>
${key.billing_address_country}