Sample Scriptable Templates

Use the following sample templates to help in creating your own custom scriptable templates:

Scriptable Issue Notification Template

The following template can be used for issue notification. This template lists key fields on the issue record and then includes all of the details entered on the issue record.

            <table>
<tr><td>Issue Number</td<td>${‌Issue.issueNumber}</td</tr>
<tr><td>Product Team</td<td>${‌Issue.productTeam}</td</tr>
<tr><td>Assigned To</td><td>${‌Issue.assigned}</td></tr>
<tr><td>Type</td><td>${‌Issue.issueType}</td></tr>
<tr><td>Severity</td><td>${‌Issue.severity}</td></tr>
<tr><td>Status</td><td>${‌Issue.issueStatus}</td></tr>
<tr><td>Link</td><td>${‌Issue.url}</td></tr>
</table>
<hr/>
<p><strong>Abstract: </strong>${‌Issue.abtract}</p>
<hr/>
<p><strong>Details:</strong> (In Reverse Chronological Order)</p>
<table>
  <#list Issue.details as detail>
    <tr>
      <td>${‌detail.author}<br/>${‌detail.date}</td>
      <td>
        ${‌detail.userNote}<#if detail.userNote != ""><br/></#if>
        <#list detail.systemNotes as systemNote>
          ${systemNote}<#if systemNote_has_next><br/></#if>
        </#list>
      </td>
    </tr>
  </#list>
</table> 

          

Scriptable Marketing Email Template

The following marketing email template is an example of a message that uses FreeMarker code to make an individualized offer to the recipient. This offer uses upsell data in NetSuite to determine correlated upsell items.

            <b>Dear <#if Customer.companyName != "">${‌Customer.companyName}<#else>Customer</#if>,</b>
 
<p>Now you have unique opportunity to get your favorite items with 20% discount!</p>
 
<p>All you need to do is to use the following coupon code when you place an order on our site: ${‌CampaignEvent.couponCode}!</p>
 
<#assign printedOutItems = 0>
<#list Customer.correlatedItems as itemLine>
  <#if 33 < itemLine.correlation>
    <img src="${itemLine.upsellItem.imageURL}" alt="${itemLine.upsellItem.displayName}" height="128" width="128"/><br/>
  </#if>
  <#assign printedOutItems = printedOutItems + 1>
  <#if printedOutItems = 3><#break></#if>
</#list> 
<#if 3 < printedOutItems>
  <#list Customer.relatedItems as itemLine>
    <img src="${itemLine.upsellItem.imageURL}" alt="${itemLine.upsellItem.displayName}" height="128" width="128"/><br/>
    <#assign printedOutItems = printedOutItems + 1>
    <#if printedOutItems = 3><#break></#if>
  </#list>
</#if>
 
<p>
  Best regards,<br/>
  <br/>
  ${preferences.MESSAGE_SIGNATURE}
</p> 

          

Scriptable Web Store Email Template

This section highlights how you can use FreeMarker to customize web store email templates. This includes how to iterate items, display item options, and customize item names. The following example code contains the essential parts you need to know to iterate items and display item options in your web store email template. Note that this example does not contain styling.

            <#list salesorder.item as itemline>
    <tbody>
        <tr>
            <!-- item image -->
            <td>
                <#if (itemimages[itemline.item.internalId])?has_content>
                    <img src="${itemimages[itemline.item.internalId]}">
                </#if>
            </td>
            <!-- item details -->
            <td>
                <!-- item name with link -->
                <div><a href="${itemurls[itemline.item.internalId]}">${‌itemline.item}</a></div>
                <!-- if it's a matrix item -->
                <#if (itemline.options)?has_content>
                    <#assign br = "<br />">
                    <#list (itemline.options)?split(br) as option>
                        <#assign label=option?substring(0,option?index_of(":")) value=(option?substring(option?index_of(":")+1))?trim>
                        <div>${label}: ${value}</div>
                    </#list>
                </#if>
                <div>Quantity: ${‌itemline.quantity}</div>
                <div>Unit Price: ${‌itemline.rate}</div>
            </td>
            <td>${‌itemline.amount}</td>
        </tr>
    </tbody>
</#list> 

          

Variable

Description

<#list salesorder.item as itemline>

Iterates over a list of sales order items using itemline in the block as the reference for the current item. This appears in a table element, with each line generating a table body and table row. Then, two cells are created for each row, with the second split into sections using divs. The first cell contains the image, which is referenced using the itemimages object. An expression is then passed that evaluates the internal ID of the item.

<img src="${itemimages[itemline.item.internalId]}">

A conditional is used to check whether the itemimages object contains content and calls it with this variable. The square brackets notation references a specific value to look for. It evaluates what is placed into it before looking up the key, similar to how JavaScript works with arrays and index references.

After that, the full product name is printed, using a technique similar to what is used for the image, except referencing the itemurls object. Both the itemimages and itemurls objects are synthetic fields that require an internal ID to function. In this example, they are used to return images and URLs using the current item line's internal ID. For more information about synthetic fields, see Synthetic Fields for Scriptable Templates.

<#if (itemline.options)?has_content>

Checks if the item options exist so they can be iterated.

<#list (itemline.options)?split(br) as option>

Item options are made into a list by splitting them up using the line break element that it contains. Each option is then split up again, by assigning the label and the value as a variable.

Item Name

The following example code demonstrates how to use FreeMarker to shorten the item name in your web store email template. By default, the full item name ${‌itemline.item} returns something similar to SPORTSWEAR : TEES & TANKS : Tranquility Tank : Tranquility Tank-M-YE.

              <!-- At the top of the loop -->
<#assign itemName = itemline.item?split(":")>

<!-- And then in the place you want it rendered -->
${itemName[itemName?size-2]?trim} 

            

Variable

Description

#assign itemName = itemline.item?split(":")

This creates an array out of the full item name, splitting it up into smaller strings each time there is a colon character.

${itemName[itemName?size-2]?trim}

Calls the variable where the name is to be rendered, but only a specific value is returned. The specific value is determined by counting the length using ?size. Then, two is deducted to obtain the second-to-last value. For example, itemName[2], provides the string for the item name, which in this case is Tranquility Tank. Then, ?trim is used to remove the white spaces at the ends.

For more information about web store email templates, see Templates for Website Email Messages.

Related Topics

General Notices