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. A useful resource for user’s new to template creation, is 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. Find the field in the NetSuite user interface and 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 preserves the enclosing quotes in your code and prevents an error when you try to save 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 using the following code:

          <#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. Direct referencing through square brackets must be handled by ?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 more than one contact names, if so 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, insert 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