Syntax for Sublist Fields

Sublists are NetSuite components that are referenced as lists of objects. The most common example of a sublist is an item sublist on a transaction, which displays a list of lines. Sublists aren't available in the Fields selector.

The most common way to access a sublist is by using the FreeMarker #list declaration. The following example shows an item sublist on the sales order.

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

        

This declaration prints out a block of HTML code to display the whole list.

          0 Name: Blue T-Shirt --- 10.00$
1 Name: Green T-Shirt --- 12.25$
2 Name: Yellow T-Shirt --- 11.00$ 

        

To reference one item in the list, you can use ${record.item[index].itemName} to obtain only that line in the sublist. Using the preceding example, ${record.item[1].itemName} returns the line 1 item Green T-Shirt.

The syntax for sublist (line item) fields is similar to body field syntax. Sublist fields are denoted with syntax like:

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> 

        

You can reference fields on a sublist at the first level only. Referencing sublists at the second level isn't supported.

For example, only the following is supported.

          <#list record.item as item>
    ${item.field_first_level}
</#list> 

        

If you use item.inventorydetail, you'll get a listing of all bin/serial numbers.

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>

Related Topics

General Notices