Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To use NetSuite's custom print button with an HTML template, follow these steps:

  1. Create an HTML template in NetSuite using the SuiteScript 2.0 HTML module or create an external HTML file and upload it to NetSuite's File Cabinet.

  2. On the record you wish to print, create a custom button and set the following properties:

  • Label: Print
  • ID: CustomPrintButton
  • Script: Leave blank
  • Function Definition: window.open('/app/site/hosting/scriptlet.nl?script=XX&deploy=YY&print=T', '_blank');

Replace XX and YY with the script ID and deployment ID of the Suitelet you will create in the next step.

  1. Create a Suitelet with the following code:

function onRequest(context) { var recordId = context.request.parameters.id; var recordType = context.request.parameters.type; var printFlag = context.request.parameters.print;

if (printFlag == "T") { var renderer = nlapiCreateTemplateRenderer(); renderer.setTemplate('<nlobjtemplate templateid="123">'); renderer.addRecord(recordType, recordId); var result = renderer.renderToString();

  context.response.writePage(result);

} else { // Return the Suitelet form here } }

Replace '123' with the ID of the HTML template you created in step 1.

  1. Deploy the Suitelet and note the deployment ID.

  2. Update the CustomPrintButton button's Function Definition with the correct script ID and deployment ID from step 4.

  3. Save the custom button and test it by opening the record and clicking the Print button. It should open a new tab with the HTML template populated with the record data.