In this blog, I will teach you how to view your reports as PDF in browsers instead of its default nature of downloading it upon access.
- SuiteScript 1.0/2.0 (required)
- Advanced PDF/HTML Templates (optional)
I will not cover the report creation stage since I am assuming that you already know how to use nlobjTemplateRenderer or ‘N/Render’ module.
Let me give you the answer immediately.
The secret is on the response headers. By default, if you created a report in NetSuite via SuiteScript its response headers is set to auto download the file. To prevent this action we must update the response headers by:
Content-Disposition: inline; filename=”report.pdf”
You must set these headers on your response object before you call your actual rendering action.
Example (SuiteScript 2.0)
// script type: Suitelet
// create template and add record logic here..
// now we set the headers
value: ‘inline; filename=”report.pdf”‘
// now we render the pdf to response
On a record, there is a button that would call this suitelet, upon clicking the button it would open a new page containing the report in PDF viewer of your browser.
That is basically it 🙂