Using FreeMarker to Include NetSuite Data in Advanced Templates

FreeMarker is a Java library that generates text outputs based on templates and dynamic data. FreeMarker is used in NetSuite. For version details, see Third-Party Products Used in Advanced Printing. You use FreeMarker interpolations to include NetSuite data in your template. An interpolation is an expression, such as ${record.entity} that FreeMarker replaces with its value in the output. A few common uses for FreeMarker declarations are provided in the following sections. For complete information about FreeMarker, see the FreeMarker documentation.

Referencing Fields

FreeMarker is commonly used to reference fields on transaction records. To reference a field, use ${record.fieldId}. In the output, this interpolation is replaced with a text representation of the field’s value.

If you want to print the field’s label, use ${record.fieldId@label}. For example, ${record.entity@label}: ${record.entity} can produce something on the Sales Order record that looks like Customer: Fabre Art Gallery.

Sublists and Other Lists

Some components in NetSuite can be referenced as lists of objects. The most common example is an item sublist on a transaction, which is represented as a list of lines. You can access values of these lists directly using the index number ${record.list[index]}. For example, adding ${record.item[1].itemName} to a sales order returns Green T-Shirt.

More commonly, you can access a list is by using the FreeMarker #list declaration, similar to the following.

            <#list record.item as item>
    ${item_index} ${item.itemName@label} ${item.itemName} --- ${item.amount}
</#list> 

          

If the item sublist on the sales order has three lines, the output looks like the following.

0 Name: Blue T-Shirt --- 10.00$

1 Name: Green T-Shirt --- 12.25$

2 Name: Yellow T-Shirt --- 11.00$

When the sublist ID is the same as the field ID, @list is added to the sublist ID. The correct syntax appears in the Fields selector automatically. The following example shows the syntax to access a sublist:

            <#list customer.currency@list as customerCurrency>
 ${customerCurrency.currency} <br/>
 ${customerCurrency.balance}
</#list> 

          

To view the sublists that are supported for a record, see the Advanced Templates Reference.

For more information about using FreeMarker expressions in advanced PDF/HTML templates, see Adding and Removing Currency Symbols in Advanced Template Fields. The training video on that page shows how to include field IDs and sublists from NetSuite transaction records in advanced templates.

Additional Information to Include on Templates

You can access additional models on each template. These include companyInformation (Company configuration information), preferences (user preference settings usually stored as Boolean values) and user (user information).

Some templates can have additional models attached, enabling you to access additional data. For example, you can access the customer record on each statement, such as the customer email, ${customer.email}.

You can also use ${record@title} to print out the record title.

Related Topics

General Notices