The code renders a record object and a custom data source to a PDF document.
function renderingData(resultObj, workOrderRecord) {
try {
// Loading the XML file and getting its contents
let datahtml = file.load({ id: }).getContents();
// Creating a renderer object
let renderer = render.create();
renderer.templateContent = datahtml;
// Adding a custom data source
renderer.addCustomDataSource({
format: render.DataSource.OBJECT,
alias: 'resultObj',
data: resultObj
});
// Adding a record object
renderer.addRecord('record', workOrderRecord);
// Rendering the data as PDF
let renderData = renderer.renderAsPdf();
renderData.name = "";
return renderData;
} catch (e) {
log.debug("error@renderingData");
return false;
}
}
To generate a PDF document, the code performs the following steps:
- It loads an XML file with the ID “”using the
file.load()function and retrieves its contents withgetContents(). This XML file likely contains the structure and layout of the PDF template. - It creates a renderer object using
render.create(). - It sets the template content of the renderer object to the XML file contents using
renderer.templateContent = datahtml. - It adds a custom data source using
renderer.addCustomDataSource(). TheresultObjis passed as an object to this data source with an alias of ‘resultObj’. This allows you to use the properties ofresultObjwithin the XML template for dynamic rendering. - It adds a record object to the renderer using
renderer.addRecord(). TheworkOrderRecordis passed as a record object to this function, allowing you to merge the record data with the XML template. - It renders the data as a PDF using
renderer.renderAsPdf(), which generates the PDF based on the XML template, custom data source, and record object. - It sets the name of the PDF file to “WO Packing Slip.pdf” using
renderData.name = "". - Finally, it returns the rendered PDF data.