In NetSuite, Advanced PDF templates use FreeMarker to generate custom documents. When working with complex records, you may encounter issues where the object seems to have content but doesn’t render as expected. This article covers troubleshooting and handling complex record objects in FreeMarker templates.
Diagnosing the Problem
- Check if the Record is Null: Use the
??operator to check if the record exists:
freemarker
Copy code
<#if record??>
<p>Record has content.</p>
<#else>
<p>Record is null or empty.</p>
</#if>
- Access Specific Fields: Instead of printing the whole object, access individual fields:
freemarker
Copy code
<p>Transaction Number: ${record.tranid}</p>
- Use FreeMarker’s Functions:
?string: Converts the object to a string.?json_string: Converts it to a JSON-formatted string.
- Example:
freemarker
Copy code
<p>Record as String: ${record?string}</p>
<p>Record as JSON: ${record?json_string}</p>
- Log the Record in SuiteScript: Before passing the record to FreeMarker, log it to ensure it contains the expected data:
javascript
Copy code
log.debug('Record Object:', myRecord);
- Access Nested Fields: For records with sub-records or lists (like items in a sales order), loop through them:
freemarker
Copy code
<#list record.items as item>
<p>Item: ${item.item}</p>
<p>Quantity: ${item.quantity}</p>
</#list>
Example Template
freemarker
Copy code
<p>Transaction Number: ${record.tranid}</p>
<p>Customer: ${record.entity}</p>
<#list record.items as item>
<p>Item: ${item.item}</p>
<p>Quantity: ${item.quantity}</p>
</#list>
<p>Record as JSON: ${record?json_string}</p>
Conclusion
When working with complex records, access fields directly and use FreeMarker functions like ?string or ?json_string to view their content. If issues persist, verify the data in SuiteScript.