NetSuite: Conditional Email Templates

When creating Email Templates, Freemarker allows us to use if statements. For instance, you want to create a template that will show the phrase "You may contact us at abc@xyz.com" to the customer, only if the customer's sales rep has an email address, where abc@xyz is the sales rep's email. If the sales rep doesn't have an email address, or if there is no sales rep, then we just show abc@xyz.com.

The if statement would look like this:

You may contact as via <#if salesrep.email != "">${salesrep.email}<#else>abc@xyz.com</#if>.

Moreover, NetSuite does not evaluate what's inside the if tag if the condition has already failed. This is useful information when we encounter compilation errors when attempting to save email templates. If we have confirmed that there is indeed nothing wrong with a template's HTML, the issue must be on the freemarker tags. The error would be a standard one, showing which lines we must look at in source mode. We simply go to the line and add an if statement to bypass the error.

For instance, we cannot save the template because of a line that contains ${custentity1}. We can try adding an if tag to check if custentity1 has any values. For this, we use the has_content built-in:

<#if custentity1?has_content>${custentity1}</#if>

Comments