Referencing Fields
FreeMarker is commonly used to reference fields on transaction records
- Syntax: ${record.fieldId}
- To print the field’s label, the syntax is: ${record.fieldId@label}
For example, ${record.entity@label}: ${record.entity}
Customer: Fabre Art Gallery
Additional Information to Include on Templates
There are additional models that can be accessed on each template. These include,
- companyInformation (Company configuration information),
- preferences (user preference settings usually stored as boolean values) and
- user (user information).
Some templates may 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.
Syntax for Advanced Template Fields
You can include the following field types for a record in an advanced template:
- body fields
- sublist fields
- fields from related records
- record search results fields
1. Syntax for Body Fields
Syntax: ${object.fieldId}
for example, ${record.entity}
■ The following objects are currently supported:
- companyInformation – company information for the current NetSuite account
For example, ${companyInformation.companyname}
- record – current transaction record
For example, ${record.trandate} is the date of the transaction.
- records – reference multiple data sources, which you typically need to do in label, check and statements templates
For example, ${statement.amountDue}.
- customer – only available on Statement records, this includes customer-related information on the template.
For example, ${customer.subsidiary} or ${customer.entityId}.
- salesorder – available on packing slips
- preferences – include settings entered on the Setup > Company > Printing & Fax page.
- user – include settings entered on the user’s Set Preferences page. These fields are typically used for emails.
Fields from records related to the current transaction record if they are of type select (not sublists).
Syntax: ${record.related_record.fieldId}
For example, to include customer field values from related item records in a sales order template, ${record.entity.email}.
Refer to custom fields, for example, include a transaction column field on a purchase order template by entering ${record.expense.custcol_cc_oversize}
■ The syntax for body fields can include an additional component,
- ${object.fieldId@label} – indicates the label of a field should be printed.
- ${record@title} – indicates that the name of the transaction record type should be printed
Fields that include a link, such as images or URLs, are enclosed in an HTML tag,
For example, <img> or <a>. You have two options for link fields:
- Use the field to include the HTML markup source.
For example, ${record.hyperlink} returns the following:
<a href src=”http://www.netsuite.com”>http://www.netsuite.com</a>
- Add @url to the field to return the link without the HTML.
For example, ${record.hyperlink@url} returns the following:
http://www.netsuite.com
2. Syntax for Sublist Fields and Other Lists
There are some components in NetSuite that can be referenced as a list of objects. The most common example is an item sublist on a transaction, which is represented as a list of lines.
The more common way of accessing a list is by using the FreeMarker #list declaration.
For example,
<#list record.item as item>
${item_index} ${item.itemName@label} ${item.itemName} — ${item.amount}
</#list>
The output would look like the following:
0 Name: Blue T-Shirt — 10.00$
1 Name: Green T-Shirt — 12.25$
2 Name: Yellow T-Shirt — 11.00$
- You can access values of these lists directly using the index number ${record.list[index]} or ${record.item[index].itemName}
For example,
${record.item[1].itemName} returns the line 1 item Green T-Shirt.
- To sort line items in advanced templates, add the sort_by() function to the #list declaration,
for example: <#list record.item?sort_by(“quantity”) as item>
You can reference fields on a sublist only at the first level. Referencing sublists at the second level is not supported.
For example, only the following is supported.
<#list record.item as item>
${item.field_first_level}
</#list>
If you use item.inventorydetail, you will get a listing of all bin/serial numbers.
3. Syntax for Address Subrecords
For address subrecords, use the following syntax in the source code:
■ Record name
■ Address subrecord name
■ Address field name
For example:
- ${subsidiary.mainaddress.addresee}
- ${subsidiary.mainaddress.addr1}
- ${subsidiary.mainaddress.addr2}
- ${subsidiary.mainaddress.city}
- ${subsidiary.mainaddress.dropdownstate}
- ${subsidiary.mainaddress.zip}
- ${subsidiary.mainaddress.country}
- ${subsidiary.mainaddress.addrphone}
4. Syntax for Fields from Joined Records and Searches
- To include fields from records directly joined to the current transaction.
Syntax: ${record.related_record.fieldId}
For Example: To include sales description field values from related item records in a sales order template,
${record.item.salesdescription}
- Include search results fields from searches joined directly to the current transaction.
Syntax: ${results[search_result_line].related_record.fieldId}
For example, to include the first customer phone number from a sales order search,
${results[0].customer.phone}
- To include a list of search results, use a list directive as shown in the following example.
<#list results as salesOrder>
<p>${salesOrder.customer.phone}</p>
</#list>