NetSuite Advanced PDF/HTML templates use FreeMarker, a Java-based template engine, to insert dynamic data into your PDF layouts. FreeMarker allows you to:
- Print field values (e.g., customer name, invoice total).
- Loop through line items.
- Apply conditions (e.g., show a field only if not empty).
- Format dates, numbers, and currencies.
Below are the most common FreeMarker syntax elements allowed in NetSuite with practical examples.
๐น Printing Fields
Use ${} to display field values.
<p>Invoice Number: ${record.tranid}</p>
<p>Customer: ${record.entity}</p>
<p>Total Amount: ${record.total}</p>
record= transaction object (Invoice, Sales Order, PO, etc.).${record.fieldId}= inserts the value of that field.
๐น Conditional Statements
Use <#if> and <#else> for logic.
<#if record.custbody_discount?has_content>
<p>Discount Applied: ${record.custbody_discount}</p>
<#else>
<p>No discount available.</p>
</#if>
โ๏ธ ?has_content checks if the field has a value.
โ๏ธ You can compare values too:
<#if record.status == "Paid">
<p><b>Thank you for your payment!</b></p>
</#if>
๐น Looping Through Line Items
Use <#list> to iterate over sublists like item.
<table border="1" width="100%">
<tr>
<th>Item</th>
<th>Quantity</th>
<th>Rate</th>
<th>Amount</th>
</tr>
<#list record.item as i>
<tr>
<td>${i.item}</td>
<td>${i.quantity}</td>
<td>${i.rate}</td>
<td>${i.amount}</td>
</tr>
</#list>
</table>
โ๏ธ record.item = item sublist.
โ๏ธ ${i.fieldId} = field inside the sublist.
๐น Formatting Dates & Numbers
NetSuite supports FreeMarker built-ins for formatting.
<p>Transaction Date: ${record.trandate?string("MMMM dd, yyyy")}</p>
<p>Total Amount: ${record.total?string["#,##0.00"]}</p>
?string("MMMM dd, yyyy")โ formats dates as โSeptember 26, 2025โ.?string["#,##0.00"]โ formats numbers with commas and 2 decimals.
๐น Escaping Null Values
If a field is empty, you can default it with !.
<p>Sales Rep: ${record.salesrep!"Not Assigned"}</p>
โ๏ธ If salesrep is empty, it shows โNot Assignedโ.
๐น Useful FreeMarker Operators in NetSuite
| Syntax | Usage Example | Result |
|---|---|---|
${field} | ${record.entity} | Prints customer |
<#if> | <#if record.total > 1000> | Conditional |
<#list> | <#list record.item as i> | Loop through lines |
?has_content | ${field?has_content} | Checks if field has value |
! | ${field!"N/A"} | Default value |
?string() | ${date?string("yyyy-MM-dd")} | Format date/number |
Leave a Reply