Hi, my client has a suitelet that creates PDF repo...
# suitescript
z
Hi, my client has a suitelet that creates PDF report, but it can be only viewed in browser. The suitelet ends with
Copy code
context.response.writeFile(renderer.renderAsPdf(), true);
Now, they want to save PDF in NetSuite File Cabinet and have access without recreating every time when need the report. My idea is to create a WorkFlow action for a custom record and first save PDF into File Cabinet, then store file id into field within custom record… Question is > How to invoke suitelet within workflow action script? Is it possible? Now they invoke suitelet from the custom page and Submit button and client script
Copy code
let suiteletUrl = url.resolveScript({
      scriptId: "customscript_popdv_export_pdf_su",
      deploymentId: "customdeploy_popdv_export_pdf_su",
      params: {......
something like this require([‘N/url’, ‘N/https’], function(url, https) { var script = ‘customscript1’; var deployment = ‘customdeploy1’; var parameters = ‘’; try { var suiteletURL = url.resolveScript({ scriptId: script, deploymentId: deployment }); var response = https.post({ url: suiteletURL, body: parameters }); log.debug(response.body.toString()); } catch(e) { log.error(e.toString()); } });
e
Can you not modify the Suitelet?
z
That's the only way... After reviewing guide about https.requestSuitelet, it is not possible to call suitelet as authenticated user... I will extract from suitelet main code for creating PDF, put into custom module and use it from suitelet and from workflow action... It is not my script, so I am afraid of side-effects
s
From within the workflow action script, you would call the suitelet which is returning the PDF file as the body of the Suitelet.
Copy code
// rest of your script

 var response = https.post({
            url: suiteletURL,
            body: parameters
        });

var PDFfile = file.create({
   name:  "YourPDFfilename.pdf",
   fileType: "PDF",
   folder : 1234,  // you must predetermine where to store it
   encoding: file.Encoding.UTF_8,
   contents : response.body
});

var PDFfileId = PDFfile.save();

// rest of your script
Although my preference would be to simply add a parameter to your suitelet URL. Something like "&savefile=T". Minimal impact to other uses of the suitelet. And inside your existing script, at the end with the response.
Copy code
let pdfFileObject = renderer.renderAsPdf();

if (param.savefile === "T") {
      pdfFileObject.name = "YourPDFfilename.pdf";
      pdfFileObject.folder = 1234;
   });
   var PDFfileId = PDFfile.save();
   context.response.write(PDFfileId);
}
else {
   context.response.writeFile(pdfFileObject, true);
}
If the workflow then calls the suitelet, it's response will be the file id which you can then return to a custom field
z
Thanks, but if I am not wrong, it is not possible to call suitelet as AUTHENTICATED USER with standard https.requestSuitelet method (as doc says only "external" mode is allowed).. in that case I must use basic https.get with OAuth2.0.....it is too complicated. I rewrote suitelet, extract all lines for creating PDF and put them into custom module. Now, suitelet and workflow action are dedicated to process different actions, one for browser viewing (as client use at this moment) and second for creating - saving - linking with custom record
💯 1