I am getting unexpected error ({"status":"Error","...
# suitescript
n
I am getting unexpected error ({"status":"Error","error":"UNEXPECTED_ERROR","detail":"An unexpected SuiteScript error has occurred"}) when I am generating PDF using:
Copy code
function printPDF(params) {
    var renderer = render.create();
    renderer.setTemplateByScriptId({
       scriptId: 'CUSTTMPL_SALE'
    });
    var lookupResult = search.lookupFields({type: search.Type.VENDOR, id: params.vendor_id, columns: ['altname']});
    renderer.addCustomDataSource({
       format: render.DataSource.OBJECT,
       alias: 'data',
       data: {
          vendor_id: params.vendor_name,
          vendor_name: lookupResult.altname
       }
    });

    renderer.addRecord({
       templateName: 'record',
       record: record.load({
          type: params.record_type,
          id: parseInt(params.record_id)
       })
    });

    return renderer.renderAsString();
}
Copy code
var fileObj = printPDF(params);
response.setHeader({
    name: 'Content-disposition',
    value: 'filename="' + params.tran_id + '"'
});
var pdfFile = render.xmlToPdf({
    xmlString: fileObj
});

response.writeFile({file: pdfFile});
But this works fine:
serverResponse.write({
output: renderer.renderAsString()
});
a
pretty sure you just need to remove the semicolon
xmlString: renderer.renderAsString()
n
No, sorry. That's a typo on my part.
I have updated the code.
a
thank you
you have any logs in there? I'd log fileObj after your prtintPDF function and log pdfFile after you've declared that just to validate they have content... but I feel like an unexpected error is something more goofy, if something was breaking in the template render, either it would return nothing, or it would return garbage