Hello,
I could use some assistance constructing the correct SS 2.0 code to render a PDF from a transaction leveraging an advanced template. In short, I am working with an estimate transaction where I've created an advanced template which I would like to consume leveraging Suitescript 2.0. The reason for this is I want to inject DocuSign dynamic content into the xml string at runtime. I think I have a pretty good foundation and the code executes successful but the PDF output is incorrect in that rather than content, the words xml.document is printed (see attached). One hack and likely part of my issue is that I am rendering to HTML 1st, so I can grab the content and alter it (not doing in this snippet). As you can see, I have to replace HTML with pdf using a regular expression since the content is wrapped in HTML tags rather than pdf tags. If there is a better way to do this, would much appreciate some direction.
/** *@NApiVersion 2.x */ // This example shows how to render an invoice into a pdf file using an xml template in the file cabinet. // Note that this example requires the Advanced PDF/HTML Templates feature require(['N/render', 'N/file', 'N/record', 'N/xml'], function(render, file, record, xml) { var transactionFile = render.transaction({ entityId: 514, printMode: render.PrintMode.HTML, formId: 100 }); var xmlStringContents = transactionFile.getContents().replace(/html/g, 'pdf'); //hacky replace log.debug('contents', xmlStringContents); // contents is valid XML wrapped with PDF var renderer = render.create(); renderer.templateContent = xmlStringContents; var customPdf = renderer.renderAsPdf(); customPdf.folder = -15; var fileId = customPdf.save(); var x = 0; debugger; }); Thanks for any help you can provide community friends!Marty