FreeMarker Syntax

Note:

Scriptable templates use the same record, field, and sublist IDs that are used in SuiteScript. Refer to the SuiteScript Records Browser for a complete list of these IDs in the Internal ID column. You can use camel case or lower case in FreeMarker code.

For complete information about using FreeMarker, see the FreeMarker website. If you're new to templates, see the Template Author’s Guide.

Tip:

To make field IDs visible, go to Home > Set Preferences and ensure that the Show Internal IDs box is checked on the General subtab, Defaults area. In the NetSuite user interface, click the field label to display the field level help text and the field ID in a popup window.

When inserting certain HTML elements such as font or color tags within the FreeMarker code, insert BEGIN and END tags to the syntax like so:

          <#--FM:BEGIN--><font color="<#if (customer.overdueBalance > 0)>red<#else>blue</#if>">Customer Account Health</font><#--FM:END--> 

        

This keeps the enclosing quotes in your code and prevents errors when saving the template.

You can get values for fields that appear in the body of a record (as opposed to on a record’s sublists) using the following syntax:

          ${record.field} 

        

For example, to reference the phone field on the customer record, you would use:

          ${customer.phone} 

        

You can insert values from all lines in a sublist in a scriptable template using a list directive with the following syntax:

          <#list record.sublist as sublistItem>
    ${sublistItem.field}
</#list> 

        

For example, you might use the following code to list the contacts and their email addresses for a customer:

          <#list customer.contactRoles as cr>
    ${cr.contact}, ${cr.email}
</#list> 

        

You can refer to fields from rows in sublists using the following syntax. The numeral in square brackets indicates which record from the sublist is being referenced. When referencing directly using square brackets, use the ?has_content function.

          <#if record.sublist[#]?has_content>${record.sublist[#].field}</#if> 

        

For example, to reference the name of the secondary contact on a customer record, first query to see if there are least two contact names, if yes, return the name from that sublist.

          <#if 1 < customer.contactRoles?size>${customer.contactRoles[1].contact}</#if> 

        

To include the email signature you created in your user preferences Home > Set Preferences, add the following Freemarker syntax into your scriptable email template. ${preferences.message_signature}.

For examples of scriptable templates, see Sample Scriptable Templates.

Related Topics

General Notices