Scenario
In SuiteScript 1.0, the method setTemplate(template) only passes the raw string of the template therefore, the advanced pdf template id cannot be used as its parameter. Unlike in SuiteScript 2.0, the method setTemplateById(options) can pass the internal id of the advanced PDF template.
Solution
To be able to reference/use an existing Advanced PDF Template in 1.0, download the template file and upload it on the file cabinet. Afterwards, load the file and get the value of the raw string.
- Navigate to existing Custom Advanced PDF/HTML Template (Customization > Forms > Advanced PDF/HTML Template)
- Click Edit on the selected template
- Hover over Actions > Download Template
- Upload the downloaded template file to file cabinet
On Suitelet script:
var record = nlapiLoadRecord('salesorder', 'internal id of record'); var renderer = nlapiCreateTemplateRenderer(); var getFile = nlapiLoadFile('intenal id of the template file'); var file = getFile.getValue(); renderer.setTemplate(file); renderer.addRecord('record', record); var xml = renderer.renderToString(); var PDFfile = nlapiXMLToPDF(xml); response.setContentType('PDF','PRINT.pdf'); response.write(PDFfile.getValue());