In NetSuite Advanced PDF Templates, you may need to evaluate multiple conditions to generate dynamic content. Freemarker supports nested conditions, allowing for greater flexibility. Here’s how to use them effectively.
What Are Nested Conditions?
Nested conditions are conditional statements inside other conditions. They are useful when a decision depends on multiple criteria.
Syntax for Nested Conditions
Here’s an example of a nested condition:
html
Copy code
<#if customer.isPreferred>
  <#if totalAmount gt 1000>
    <p>Thank you for being a preferred customer! You qualify for a special discount.</p>
  </#if>
</#if>
In this example:
- The inner <#if>only runs if the outer condition is true.
- The totalAmountcheck happens only for preferred customers.
Tips for Writing Nested Conditions
- Use Indentation for Readability
- Proper indentation helps distinguish between different levels of conditions.
html
Copy code
<#if itemType == "inventory">
  <#if quantity gt 10>
    <p>Bulk inventory order detected!</p>
  </#if>
</#if>
- Combine Logic to Simplify Nesting
- Use logical operators like &&to combine conditions and reduce nesting:
html Copy code <#if itemType == "inventory" && quantity gt 10> <p>Bulk inventory order detected!</p> </#if>
- Handle Else Cases
- Always consider adding an <#else>block for fallback logic.
html Copy code <#if totalAmount gt 1000> <p>You qualify for free shipping!</p> <#else> <p>Standard shipping rates apply.</p> </#if>
Common Pitfalls to Avoid
- Avoid deep nesting, as it can make your template difficult to read and debug.
- Always include null checks to prevent unexpected errors in nested conditions.
By using nested conditions wisely, you can handle complex scenarios in your NetSuite Advanced PDF Templates while maintaining clarity and reliability.