Rendering

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:

  1. It loads an XML file with the ID “”using the file.load() function and retrieves its contents with getContents(). This XML file likely contains the structure and layout of the PDF template.
  2. It creates a renderer object using render.create().
  3. It sets the template content of the renderer object to the XML file contents using renderer.templateContent = datahtml.
  4. It adds a custom data source using renderer.addCustomDataSource(). The resultObj is passed as an object to this data source with an alias of ‘resultObj’. This allows you to use the properties of resultObj within the XML template for dynamic rendering.
  5. It adds a record object to the renderer using renderer.addRecord(). The workOrderRecord is passed as a record object to this function, allowing you to merge the record data with the XML template.
  6. 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.
  7. It sets the name of the PDF file to “WO Packing Slip.pdf” using renderData.name = "".
  8. Finally, it returns the rendered PDF data.

Leave a comment

Your email address will not be published. Required fields are marked *