Using SuiteScript for Transaction Records

How SuiteScript APIs Work

The SuiteScript API lets you programmatically extend NetSuite beyond the capabilities offered through SuiteBuilder customization. Most SuiteScript APIs pass record, field, sublist, tab, search filter, and search column IDs as arguments.

To determine which script you need, refer to the SuiteScript documentation. To get started with the SuiteScript 2.x API, see SuiteScript 2.x API Reference.

After you have determined which script you need, perform the following steps to get a script to run in NetSuite.

  1. Create your script.

  2. Create a NetSuite Script record for your script. You will be prompted to load the script file.

  3. Create a NetSuite Script Deployment record and specify script runtime options.

For complete details on each step in the process, start with the SuiteScript 2.x API Introduction topic in the NetSuite Help Center.

SuiteScript 2.x Module and Members for Printing Transaction Records

SuiteScript 2.x supports a render module that you can use you to programmatically print, create PDFs, create forms from templates, and create email messages from templates.

The render.TemplateRenderer object member provides a template engine object and related methods so you can use advanced PDF/HTML templates to produce HTML and PDF printed forms. For details, see render.TemplateRenderer. If you associate an advanced template with the custom form saved for a transaction and use this API to print the transaction, the advanced template is used to format the printed transaction.

In SuiteScript 2.x, it is possible to reference a template by ID. The N/render Module includes a method that supports referencing a template by its script ID, TemplateRenderer.setTemplateByScriptId. Each template's script ID can be set and reviewed in the Template Setup popup window of the Template Editor.

In addition to the method for referencing templates by script ID, the TemplateRenderer.setTemplateById method supports referencing a template by its system-generated internal ID. This method would only be required for specific custom printing solution use cases.

For information about the NetSuite records that support SuiteScript, see SuiteScript Supported Records.

Advanced Template List for Custom Printing Solutions

When your create a custom field of type List/Record, Advanced PDF/HTML Templates is available as an option in the List/Records dropdown list on the custom field setup page available at Customization > Lists, Records & Fields > [Custom Field]. This option provides users with a list of all available advanced templates, for use in a case where you create a script that enables users to specify a form to be used for printing, as part of a custom printing solution.

For example, to provide a custom printing solution for your users you could create a purchase order form and add a custom field of type List/Record with Advanced PDF/HTML Templates specified. Then you use the SuiteScript 2.x N/render Module to refer to each user’s selected advanced template by NetSuite internal ID. A Suitelet can then be used to take the user's selection and pass in the internal ID of the template to print the purchase order.

Notes about Advanced Template List

  • This option should be used only with a scripted custom printing solution.

  • The list of available templates is not filtered. All advanced PDF/HTML templates are available, including those that are not for the correct transaction type.

  • This field alone does not allow users to specify the template to be used for printing a form. By default, printing preferences for advanced forms are specified by Setting Custom Forms to Use Advanced Templates.

Printing the Correct Currency Symbol

If you are using SuiteScript to render saved search results, verify the following to ensure that the correct currency symbol is used in the advanced PDF/HTML template.

  1. Add Currency to the saved search columns.

  2. Use code something similar to the following in the JavaScript file.

            <#if result.currency == 'Euro'>${result.fxamountremaining?string('#,##0.00')} €
<#elseif result.currency == 'USA'>${‌result.fxamountremaining}
</#if> 

          

SuiteScript 2.x for Transaction Records

SuiteScript 2.x supports a template engine object and related methods so you can apply advanced template format capabilities programmatically. For details, see render.create() and render.TemplateRenderer. For information about the NetSuite records that support SuiteScript, see SuiteScript Supported Records.

In addition to this function and object, the N/render Module supports the use of advanced templates. If you associate an advanced template with the custom form saved for a transaction and use this API to print the transaction, the advanced template is used to format the printed transaction.

You can also use SuiteScript to apply advanced templates to printed records that are not transactions. For information, see Using SuiteScript to Apply Advanced Templates to Non-Transaction Records.

Printing a Large Volume of Documents

To print hundreds or thousands of documents, you must use the SuiteScript API and follow these steps.

To print a large volume of documents:

  1. Create a Saved Search of the documents that you want to print. If you need to print out more than 1000 documents, create multiple searches where you batch results of 1000 rows or fewer.

  2. Create the Template using the <pdfset> tag. The <pdfset> tag specifies that everything between the <pdf> tags will be processed separately, which improves the efficiency of the printing algorithm.

                        <?xml version="1.0"?>
    <!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd">
    <pdfset>
    <#list results as result> <pdf> <head> </head> <body> <h1 align="right">Invoice</h1> <p align="right">#${‌result.tranid}</p> <p align="right">${‌result.trandate}</p> <p>Total: ${‌result.amount}</p> </body> </pdf>
    </#list>
    </pdfset> 
    
                      
  3. Write the script file, including nlapiSearchRecord to call the saved search and nlapiCreateTemplateRenderer to generate the documents.

  4. Create a Suitelet and attach the SuiteScript to it, selecting the appropriate function to execute.

Related Topics

Scripting with Advanced Templates
Using Custom Data Sources for Advanced Printing
Using SuiteScript to Apply Advanced Templates to Non-Transaction Records
Using SuiteScript 2.x to Combine Multiple Data Sources in One Advanced Template

General Notices