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