ANS-1549 · SUITESCRIPT DEVELOPMENT
How to Specify a Custom Form When Printing Records in NetSuite SuiteScript 2.x
This guide explains how to use the N/render module in SuiteScript 2.x to print transaction records and apply a specific custom form.
Short answer
To print a NetSuite record using a specific custom form in SuiteScript 2.x, leverage the N/render module. Utilize the render.transaction() method for transactions, passing the record's internal ID, desired print mode, and the custom form's internal ID via the formId parameter in the options object. This ensures the correct form template is applied to the generated output.
Scenario
Users often need to generate printable versions of NetSuite records, such as invoices or sales orders, but require these documents to adhere to a specific custom form layout rather than the default. The challenge is to programmatically specify which custom form should be used when initiating the print action via SuiteScript.
Solution
To specify a custom form when printing a record in SuiteScript 2.x, the N/render module should be utilized. This module provides methods for generating printable outputs, such as PDFs, from NetSuite records. For transaction records, the render.transaction() method is used.The render.transaction() method accepts an options object where the formId parameter can be set to the internal ID of the desired custom form.Below is an example demonstrating how to print a transaction record as a PDF using a custom form. This snippet assumes it is executed within a SuiteScript 2.x context where the N/render module is loaded:
javascriptvar render = require('N/render');var recordId = 123; // Replace with the internal ID of the transaction recordvar pdfOutput = render.transaction({ entityId: recordId, printMode: render.PrintMode.PDF, formId: 200 // Internal ID of the custom form});This code will generate a PDF file for the specified transaction, applying the custom form identified by formId: 200. The pdfOutput variable will contain a N/file.File object representing the generated PDF.
Expert NetSuite Support
Need help with this NetSuite issue?
SuiteScript Development consulting and configuration support
