7px
09/11/2023, 6:26 AMN/render module, the function render.renderAsPdf(), binding an Advanced PDF/HTML Template, as well as a Transaction record to it. However, I also want to attach other values from fields within the record, primarily the mainaddress field of the Customer field, which can't be accessed through my initial thought of ${record.customer.mainaddress} within the template. Is there a way to add other values to the TemplateRenderer object before it renders the file, that aren't on the record being attached itself? I could go and add custom fields on the record that fetch the values needed, but i feel that that adds unnecessary bloat on a record that doesn't need those details. I plan on just fetching the values i need before calling renderAsPdf().
any help would be appreciated, thanks.CD
09/11/2023, 6:42 AMNElliott
09/11/2023, 7:21 AMClay Roper
09/11/2023, 1:12 PMNElliott
09/11/2023, 1:14 PM7px
09/29/2023, 8:50 AMTemplateRenderer.addCustomDataSource() was the correct approach.
For anyone who might search in the future, I was using an Advanced PDF/HTML Template instead of an XML file, so there were minor adjustments to the approach but it is fundamentally the same. I've also learned later on you can, as mentioned by @Clay Roper that you can actually append multiple values in the custom data object, but in my case, I just needed one field. Here are snippets of code:
in the suitelet script:
//...
let renderer = render.create()
let customdata = { add: customer_record.getValue({ fieldId: "defaultaddress" }) };
renderer.addCustomDataSource({ format: render.DataSource.OBJECT, alias: "custrecord", data: customdata });
//...
in my advanced template:
<!-- somewhere in <body> -->
<br/>${custrecord.add}
<!-- ... -->
do note that upon saving, the Advanced Template will call out this declaration as an error, since it doesn't recognize whatever you use for an alias in your customDataSource, so don't be afraid if the template complains on saving. There's probably a workaround for negating this popup warning, but since this isn't impeding my workflow and it works as intended, I'm leaving it as is for now.