Have you tried incorporating Freemarker into your NetSuite email templates?

Using Freemarker in NetSuite could be intimidating, especially if you do not have a programming background.

Nevertheless, learning about Freemarker is much easier than learning SuiteScript. Plus, it is beneficial for you as a NetSuite Administrator to practice it as it could achieve different use cases without having to write a code.

For example, on your template, you could put a tag like ${customer.entityId} that could automatically display the name of the customer when an email is sent.

In the following step-by-step guide, I am going to demonstrate a simple use case where you could practice your Freemarker skills.

Disclaimer: This article only serves as a sample guide. You must thoroughly test all use cases to gauge if Freemarker is applicable to your business needs. Never apply this directly to your Production account!
  1. Go to Documents > Templates > Email Templates > New.2 Text Editor

  2. Enter a name.

  3. Under the “Templates” tab, select the “Text Editor” radio button.6 Email Body

  4. You will notice that the field internal ID will appear on body upon toggling the field. 4 Field Type
    You can copy this field ID and put it on the subject to make your email subject dynamic.5 Transaction ID

  5. You may add some text or other fields as you wish. See sample subject below:

    ${transaction.tranId} is due on ${transaction.dueDate}
  6. On the text editor, add some text that will define your email body. An important thing to note is that when you’re referencing fields, do not limit yourself to “Transaction” fields. If you’d like a dynamic customer name to whom you’re going to address your email, for example, select the “Customer” as the Field Type and the field you’re using to define the name.

  7. To add Freemarker elements to your template, click on the “hashtag” icon.7 Freemarker email template

  8. You will see something like <#if ></#if> in your email body. This is where you add your Freemarker statements.

    Note that when adding field IDs to your Freemarker statements, you must remove the curly braces and dollar sign. e.g.

    Text Editor = ${employee.entityId}
    Freemarker = employee.entityId

  9. Here’s your sample Freemarker “if statement”. This statement means that if the transaction’s subsidiary is “Subsidiary A”, display “123456789”. If it’s “Subsidiary B”, display “987654321”. You can tweak it as you like based on the said syntax.


    <#if transaction.subsidiary == "Subsidiary A"> 123456789
    <#elseif transaction.subsidiary == "Subsidiary B"> 987654321
    </#if>

    As a bonus, here’s my complete template:

    Dear ${customer.entityId},
    
    This is to remind you that Invoice #${transaction.tranId} amounting to ${transaction.total} is due on ${transaction.dueDate}.
    
    Kindly settle the payment on the following bank account:
    
    Bank Account Number:
    <#if transaction.subsidiary == "Subsidiary A"> 123456789
    <#elseif transaction.subsidiary == "Subsidiary B"> 987654321
    </#if>
    
    Regards,
    ${employee.entityId}
  10. Congrats on your first NetSuite scriptable email template with Freemarker! Now you may test this by clicking on the “Email” button on the transaction and selecting the template that you just created yourself.

    10 Email Test

LEACC Consultancy is a team of NetSuite Consultants who are experts in  NetSuite Administration, customization, SuiteScript 2.0 and SuiteScript 1.0. Our team has worked with 400+ NetSuite scripts and workflows combined. We have also administered multiple NetSuite accounts with hundreds of users. If you need some help in NetSuite Development and NetSuite Administration, contact us by filling out this form or by commenting below. Did you find this article helpful? Feel free to request for more articles like this!

Leave a Reply