Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer peopleโ€™s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer peopleโ€™s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The NetSuite Pro

The NetSuite Pro Logo The NetSuite Pro Logo

The NetSuite Pro Navigation

  • Home
  • About Us
  • Tutorials
    • NetSuite Scripting
    • NetSuite Customization
    • NetSuite Integration
    • NetSuite Advanced PDF Templates
    • NetSuite Reporting & Analytics Guide
    • Real-World NetSuite Examples
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask A Question
  • Home
  • About Us
  • Tutorials
    • NetSuite Scripting
    • NetSuite Customization
    • NetSuite Integration
    • NetSuite Advanced PDF Templates
    • NetSuite Reporting & Analytics Guide
    • Real-World NetSuite Examples
  • Blog
  • Contact Us
Home/ NetSuite Customization Guide: Fields, Forms, Workflows & Scripts/Creating Dynamic Email Templates in NetSuite (FreeMarker + SuiteScript)

Creating Dynamic Email Templates in NetSuite (FreeMarker + SuiteScript)

๐Ÿ’Œ Creating Dynamic Email Templates in NetSuite (FreeMarker + SuiteScript)

Introduction

NetSuite provides a flexible way to design and automate custom email templates โ€” perfect for invoices, order confirmations, customer communications, and workflow notifications.

Using FreeMarker syntax, you can dynamically insert record data into templates. Combine that with SuiteScript or SuiteFlow, and you can send personalized, branded emails that automatically trigger during business processes.

This tutorial walks you through:

  • Creating email templates using FreeMarker
  • Adding dynamic record fields and logic
  • Sending templates via SuiteScript or workflows
  • Pro tips for styling and testing

๐Ÿ’ก Why Use Custom Email Templates?

GoalExample
Personalized EmailsInclude customer name, order total, and expected ship date
Automated NotificationsTrigger emails after fulfillment or approval
Professional BrandingAdd logos, HTML styling, and signatures
Multi-language MessagingShow content dynamically based on customer locale
Marketing or EngagementSend reactivation or renewal reminders

๐Ÿงฑ Step-by-Step: Creating a Custom Email Template

Step 1: Navigate to Template Setup

Go to:
Documents โ†’ Templates โ†’ Email Templates โ†’ New

Step 2: Add Template Information

FieldDescription
NameUnique template name (e.g., Order Confirmation Template)
Record TypeSelect record the template will be tied to (e.g., Sales Order)
Available ForEmail, Workflow, or Script
SubjectUse FreeMarker variables (e.g., Order #${transaction.tranid})

Step 3: Add Body Content with FreeMarker

In the body editor, you can use FreeMarker syntax to pull data dynamically:

<p>Dear ${customer.entityid},</p>

<p>Thank you for your order <strong>#${transaction.tranid}</strong> placed on 
${transaction.trandate?string("MMMM dd, yyyy")}.</p>

<p>Your order total is <strong>${transaction.total}</strong>.</p>

<p>You can view your order here: 
<a href="https://{{companyURL}}/app/accounting/transactions/salesord.nl?id=${transaction.id}">
View Order Details</a></p>

<p>Best regards,<br/>
${companyInformation.companyname} Team</p>

โœ… Tip: Use ${record.fieldid} or ${transaction.fieldid} for record-level values.


Step 4: Add Company Branding (Optional)

Use inline CSS for styling:

<div style="font-family:Arial; font-size:14px;">
  <h2 style="color:#0066cc;">Order Confirmation</h2>
  <p>Thank you for choosing ${companyInformation.companyname}!</p>
</div>

You can also insert your logo:

<img src="https://yourdomain.com/images/logo.png" width="200"/>

Step 5: Test the Template

  • Click Preview to test data placeholders.
  • Select a sample record (e.g., a Sales Order).
  • Verify all variables render correctly (not blank or missing).

๐Ÿง  FreeMarker Quick Reference

FreeMarker FunctionExampleDescription
${field}${transaction.tranid}Displays field value
<#if><#if transaction.total > 500>Conditional logic
<#list><#list transaction.item as line>Loop through lines
<#assign><#assign totalLines = transaction.item?size>Create variable
<#include><#include "footer.ftl">Include another template

Example: Add Conditional Section

<#if transaction.status == "Pending Approval">
<p style="color:red;">Your order is pending approval.</p>
<#else>
<p>Your order is being processed.</p>
</#if>

Example: Loop Through Line Items

<table border="1" cellpadding="6">
<tr><th>Item</th><th>Qty</th><th>Rate</th><th>Amount</th></tr>
<#list transaction.item as line>
<tr>
  <td>${line.item@label}</td>
  <td>${line.quantity}</td>
  <td>${line.rate}</td>
  <td>${line.amount}</td>
</tr>
</#list>
</table>

โš™๏ธ Sending Emails via SuiteScript

Once your template is created, send it from any script (User Event, Workflow, or Suitelet):

/**
 * @NApiVersion 2.1
 */
define(['N/email', 'N/record', 'N/runtime'], (email, record, runtime) => {
    const sendOrderEmail = (salesOrderId) => {
        email.send({
            author: runtime.getCurrentUser().id,
            recipients: 'customer@example.com',
            subject: 'Your Order Confirmation',
            body: email.merge({
                templateId: 123, // ID of your email template
                entity: { type: 'customer', id: 456 },
                transactionId: salesOrderId
            }).body
        });
    };
    return { sendOrderEmail };
});

โœ… Result:
The system merges your FreeMarker email template with the Sales Order data and sends a professional, dynamic email.


๐Ÿ’ก Integrating Email Templates in Workflows

  1. Create a Workflow on a record (e.g., Sales Order).
  2. Add a State โ†’ Action โ†’ Send Email.
  3. Choose your custom template.
  4. Set condition (e.g., Status = โ€œBilledโ€).
  5. Schedule or trigger on field change.

Result:
Automatic email notifications with dynamic data and branding.


๐Ÿงฉ Real-World Use Cases

ScenarioDescription
Order ConfirmationTriggered when Sales Order is approved
Invoice ReminderSent when invoice due date approaches
Shipment NotificationSent when Item Fulfillment is completed
Customer WelcomeWorkflow email when new Customer is created
Payment ReceiptAuto-send when Payment record is saved

โšก Styling & Best Practices

  • Use inline CSS (external stylesheets are not supported).
  • Avoid images over 200 KB to improve deliverability.
  • Use plain text fallback for critical notifications.
  • Add tracking parameters (UTM) for marketing emails.
  • Test across email clients (Gmail, Outlook, Apple Mail).
  • Use Preview Template for validation before live use.

๐Ÿงฎ Common Issues & Fixes

ProblemCauseSolution
Variables not showingWrong record contextUse correct field path (e.g., transaction.total)
HTML brokenUnclosed tagsUse online validator before saving
Template not selectable in scriptMissing โ€œAvailable For: Scriptโ€ optionEnable before saving
No preview dataNo sample record selectedChoose record when previewing

๐Ÿ“š Related Tutorials

  • ๐Ÿ‘‰ Custom Buttons & Actions in NetSuite
  • ๐Ÿ‘‰ Advanced PDF Templates with FreeMarker
  • ๐Ÿ‘‰ Automating Approvals with SuiteFlow

โ“ FAQ

Q1. Can I attach files or PDFs to emails sent via templates?
Yes โ€” in SuiteScript, use the attachments parameter in email.send() to attach PDFs or files.

Q2. Can I include custom fields in templates?
Yes, use ${transaction.custbody_fieldid} or ${customer.custentity_fieldid}.

Q3. Can I send different templates based on role or region?
Yes โ€” create multiple templates and use conditions in workflows or script logic.

Q4. Is there a size limit for email templates?
Yes, up to ~50 KB HTML content is recommended for optimal rendering.


๐Ÿงญ Summary

Custom Email Templates in NetSuite make communication personalized, automated, and professional.
By combining FreeMarker logic and SuiteScript, you can deliver dynamic, data-driven messages that match your business workflow โ€” without manual intervention.

Mastering this feature not only streamlines communication but also builds stronger customer relationships.

Share
  • Facebook

Leave a ReplyCancel reply

Sidebar

Ask A Question

Stats

  • Questions 6
  • Answers 6
  • Best Answers 0
  • Users 2
  • Popular
  • Answers
  • Rocky

    Issue in running a client script in NetSuite SuiteScript 2.0 ...

    • 1 Answer
  • admin

    How can I send an email with an attachment in ...

    • 1 Answer
  • admin

    How do I avoid SSS_USAGE_LIMIT_EXCEEDED in a Map/Reduce script?

    • 1 Answer
  • admin
    admin added an answer The issue is usually caused by following Wrong script file… September 14, 2025 at 10:33 pm
  • admin
    admin added an answer Steps to send an Invoice PDF by email: define(['N/email', 'N/render',… August 28, 2025 at 3:05 am
  • admin
    admin added an answer This error means your script hit NetSuiteโ€™s governance usage limit… August 28, 2025 at 3:02 am

Top Members

Rocky

Rocky

  • 1 Question
  • 22 Points
Begginer
admin

admin

  • 5 Questions
  • 2 Points

Trending Tags

clientscript netsuite scripting suitescript

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

© 2025 The NetSuite Pro. All Rights Reserved