AgileApps Support Wiki Pre Release

Difference between revisions of "Email Templates"

From AgileApps Support Wiki
imported>Aeric
Β 
(87 intermediate revisions by 2 users not shown)
Line 1: Line 1:
'''Workspace > All Items > Templates'''
'''[[File:GearIcon.png]] > Objects > {object} > Email Templates'''


Email templates define a standard look for [[Email]] correspondence that can be customized for individual messages.
__TOC__
==About Email Templates==
==About Email Templates==
The Templates object stores ''email templates'' used in [[Campaigns]] and in general correspondence. Β 
''Email templates'' are used to create an email-based conversation centered on a specific object record. The ''variables'' they contain are replaced with record data, to create a customized message.
:''For other kinds of templates, see [[Templates (disambiguation)]]''


Templates are created using an online editor, or by pasting in HTML created in an external editor.
You can create new templates, and modify the ones that already exist.
Β 
Templates can also include variables to information so you can personalize each email that goes out.
Β 
{{Tip|If [[Email to Case]] has been set up, use an Email-to-Case mailbox as the "From" address. Replies to the message are then automatically recorded as part of the Case.
:''Learn more:'' [[Sample Template for use with Email-to-Case]]}}


==Working with Email Templates==
==Working with Email Templates==


===Create an Email Template ===
===Creating an Email Template===
Β 
# Go to '''[[File:GearIcon.png]] > Objects > {object} > Email Templates'''
#Click '''Workspace > All Items > Templates'''.<br>The Templates object opens.
# Click '''[New Email Template]'''
#Click the '''[New Template]''' button.
# Choose the editor you want to use to create the template content (WYSIWYG '''HTML Editor''', '''RAW HTML''' (HTML tags) editor, or '''Plain Text''' editor.
#Specify whether to '''Use for Email-to-Case Interactions'''.
#: (It's best to choose one editor and stick with it. Formatting tends to be lost when switching.)
#Select your template design method.
# Use the Template Variable tool at the top of the page to insert [[Template Variables in Email Templates|template variable]] placeholders into the template.
Β 
# Click '''[Save]'''
<span id="email-to-case">;Email-to-Case Interactions:</span>
With this option:
:* The template is available for use automated responses and customer-notifications in [[Email to Case]] settings (and is only available in that context).
:* The following variables become available in the template, derived from the initial email that created the Case (in addition to the normal Case variables):
:: <tt>Email To, Email From, Email Cc,<br>Email Subject, Email Body, Email Reply To,<br>Email Size, Email Headers</tt>
Β 
;Design Methods:
{{:Editors}}
Β 
===Use the HTML Editor Toolbar===
The toolbar appears when using the free-form HTML editor.
Β 
:{{:Editing Toolbar}}
Β 
===Add Template Variables===
Use Template Variables to personalize email templates:
:* From any template editor, Click the ''Show Template Fields'' link.<br>The [[Template Variable Tool]] pops up.
:* Select a category and a field.<br>The name for the field appears in the Variable column. (For example:<tt>$Customer.discount</tt>.)
:* Copy the variable name, close the popup, and insert the variable into your template.
Β 
:''For a list of Template Variables, see:'' [[Template Variables in Email Templates]]
Β 
===Add Personalized Merge Fields===
Create Personalized Merge Fields in custom email templates.
:{{:Personalized Merge Fields}}
Β 
===Add Images===
In HTML, an image is referenced using a tag that has the form: <tt><nowiki><image src"..."></nowiki></tt>, where the <tt>src</tt> attribute contains an absolute or relative path to the image. That path can be a file path like <tt>../images/local_image_file.jpg</tt> or it can be a URL of the form <tt><nowiki>http://...</nowiki></tt>.
Β 
When the email arrives in a recipient's inbox, file paths are obviously of little value. (They would only work if recipient happened to have all of the right images at the right locations on their local system. Small chance!) So Http URLs are used to access the images.
Β 
To generate those URLs, the images to be included in the URLs need to be uploaded to the platform as [[Public Document]]s. URLs for those images become available when they are made public. You then insert those URLs into the <tt><nowiki><image src"..."></nowiki></tt> tags.
Β 
The resulting tag as the form <tt><image src="{{platformURL}}/..."></tt>. The link then works in the recipient's email, because the image is publicly available.
Β 
==Sample Templates==
Use these samples as a starter for the <tt>body</tt> of an email template.
Β 
===Sample Template for use with Email-to-Case===
When an email is sent using this template, the recipient is prompted to reply in a way that allows their comments to be recorded as part of the case.
:<syntaxhighlight lang="html4strict" enclose="div">
<blockquote>
<p align="center">Please type your response ABOVE THIS LINE when replying. </p>
<hr />
$__current_note__.message
</p>
Β 
<p>For the fastest follow-up, reply to this email, which references Case #$Case.case_number.</p>
<hr />
<b>Previous Messages</b>
<hr />


<table>
{{Tip|The easiest way to create your own template is to start by copying one that is close to what you want. That way, many of the variables you need are already in the template body.}}
#foreach($Previous_Notes_Item in $__previous_notes__)
<tr>
<td colspan="2"><p>$Previous_Notes_Item.date_modified<br />
$Previous_Notes_Item.created_by_name <b>replied</b><br />
</p> </td>
</tr>
<tr>
<td width="30">&nbsp;</td>
<td width="739">$Previous_Notes_Item.message</td>
</tr>
<tr>
<td colspan="2"><hr /></td>
</tr>
#end
</table>
<p align="center"><font size="-1">This message was sent to $Case.from_address in reference to Case #$Case.case_number</font></p>
</blockquote>
</syntaxhighlight>


===Sample Template for use with Service Portal===
===Editing an Email Template===
When an email is sent using this template, the user is informed that they can use the Service Portal to follow up on their case. Β 
# Go to '''[[File:GearIcon.png]] > Objects > {object} > Email Templates'''
:<syntaxhighlight lang="html4strict" enclose="div">
# Select an existing template.
<blockquote>
# Choose the editor you want to use to create the template content (WYSIWYG '''HTML Editor''', '''RAW HTML''' (HTML tags) editor, or '''Plain Text''' editor.
$__current_note__.message
#: (It's best to choose one editor and stick with it. Formatting tends to be lost when switching.)
# Use the Template Variable tool at the top of the page to add [[Template Variables in Email Templates|template variable]] placeholders.
# Click '''[Save]'''
{{:Common:HTML Editor Tip}}


<p>For the fastest follow-up, use the <a href="__URL HERE__">Service Portal</a> and reference Case #$Case.case_number.</p>
===Choosing Template Variables===
<hr />
The section at the top of the page gives you variables you can use in the template. The list may varies, depending on the type of template you're creating. Here are some of the standard categories:
<b>Previous Messages</b>
<hr />


<table>
:{| border="1" cellpadding="5" cellspacing="1"
#foreach($Previous_Notes_Item in $__previous_notes__)
| valign="top"Β  colspan="2" | '''Case Templates'''
<tr>
|-
<td colspan="2"><p>$Previous_Notes_Item.date_modified<br />
||
$Previous_Notes_Item.created_by_name <b>replied</b><br />
:'''User -''' Fields related to the current logged in user.
</p> </td>
:'''Company -''' Fields related to the [[Company Information]] settings data.
</tr>
:'''Date and Time -''' Fields related to the current date and time.
<tr>
:'''Custom Variables -''' Special variables that are available to all templates. You can add and modify them as per the requirement.
<td width="30">&nbsp;</td>
|}
<td width="739">$Previous_Notes_Item.message</td>
'''How to get a template variable?'''
</tr>
# Click the '''Category''' dropdown and select the desired option you want to access.<br>(The list varies with the email template type.)
<tr>
# Click the '''Field''' and select the desired field.
<td colspan="2"><hr /></td> Β 
# Copy the text that appears in the '''Variable''' field, and paste it into one of the template fields.
</tr>
#: '''For example''', <tt>From Name: ''$user.full_name</tt>''; <tt>From Email Address: ''$user.full_name</tt>''; <tt>Subject: ''$user.company</tt>''.
#end
</table>
<p align="center"><font size="-1">This message was sent to $Case.from_address in reference to Case #$Case.case_number</font></p>
</blockquote>
</syntaxhighlight>


===Combined Sample Template===
===Specifying Template Content===
This template assumes that both [[Email to Case]] and a [[Service Portal]] have been configured. Β 
;Basic Information:
:<syntaxhighlight lang="html4strict" enclose="div">
:* '''Template Name -''' The name that appears in the list of templates.
<blockquote>
:* '''Type -''' When this field is present, it is possible to specify multiple template types, which determines where it can be used and which template variables are available.
<p align="center">Please type your response ABOVE THIS LINE when replying. </p>
:* '''From Name -''' The name that indicates the person or department the email came from. For example, "Company Support".
<hr />
:* '''From Address -''' The email address that end-user replies will go to. (See the note below)
:* '''Subject -''' Subject for the message. Β 
:* '''Message -''' Choose how you want to compose the message:
::* Use the WYSIWYG '''HTML Editor'''
::* Paste HTML code written in an external editor into the '''RAW HTML''' window
::* Write a '''Plain Text''' message


$__current_note__.message
;Attachments:
Choose one or more of the [[Document Templates]] you've created to encapsulate Case data. The document is generated from the data and attached to the message.
{{Note|
# It is not possible to choose a Document Template that is based on a JSP page.
# You may expect a delay in receiving an email when you include attachments (File Field, Image Field, and Document Template).}}
:''Learn more:'' [[JSP Attachment Deprecation]]


<p>For the fastest follow-up, reply to this email, or use the <a href="__URL HERE__">Service Portal</a> and reference Case #$Case.case_number.</p>
===Adding an Image===
<hr />
{{:Common:Adding Images to Templates}}
<b>Previous Messages</b>
<hr />


<table>
==Processing Related Records==
#foreach($Previous_Notes_Item in $__previous_notes__)
{{:Common:Processing Related Records in HTML}}
<tr>
<td colspan="2"><p>$Previous_Notes_Item.date_modified<br />
$Previous_Notes_Item.created_by_name <b>replied</b><br />
</p></td>
</tr>
<tr>
<td width="30">&nbsp;</td>
<td width="739">$Previous_Notes_Item.message</td>
</tr>
<tr>
<td colspan="2"><hr /></td>
</tr>
#end
</table>
<p align="center"><font size="-1">This message was sent to $Case.from_address in reference to Case #$Case.case_number</font></p>
</blockquote>
</syntaxhighlight>
<noinclude>
<noinclude>


[[Category:Tutorials]]
[[Category:Customizing the Application]]
[[Category:Object Aspects]]
[[Category:Design]]
</noinclude>
</noinclude>

Latest revision as of 09:21, 28 June 2023

GearIcon.png > Objects > {object} > Email Templates

About Email Templates

Email templates are used to create an email-based conversation centered on a specific object record. The variables they contain are replaced with record data, to create a customized message.

You can create new templates, and modify the ones that already exist.

Working with Email Templates

Creating an Email Template

  1. Go to GearIcon.png > Objects > {object} > Email Templates
  2. Click [New Email Template]
  3. Choose the editor you want to use to create the template content (WYSIWYG HTML Editor, RAW HTML (HTML tags) editor, or Plain Text editor.
    (It's best to choose one editor and stick with it. Formatting tends to be lost when switching.)
  4. Use the Template Variable tool at the top of the page to insert template variable placeholders into the template.
  5. Click [Save]

Thumbsup.gif

Tip: The easiest way to create your own template is to start by copying one that is close to what you want. That way, many of the variables you need are already in the template body.

Editing an Email Template

  1. Go to GearIcon.png > Objects > {object} > Email Templates
  2. Select an existing template.
  3. Choose the editor you want to use to create the template content (WYSIWYG HTML Editor, RAW HTML (HTML tags) editor, or Plain Text editor.
    (It's best to choose one editor and stick with it. Formatting tends to be lost when switching.)
  4. Use the Template Variable tool at the top of the page to add template variable placeholders.
  5. Click [Save]

Thumbsup.gif

Tip: When using the HTML editor, press Alt+0 (Alt key plus zero) to get a list of shortcut keys.

Choosing Template Variables

The section at the top of the page gives you variables you can use in the template. The list may varies, depending on the type of template you're creating. Here are some of the standard categories:

Case Templates
User - Fields related to the current logged in user.
Company - Fields related to the Company Information settings data.
Date and Time - Fields related to the current date and time.
Custom Variables - Special variables that are available to all templates. You can add and modify them as per the requirement.

How to get a template variable?

  1. Click the Category dropdown and select the desired option you want to access.
    (The list varies with the email template type.)
  2. Click the Field and select the desired field.
  3. Copy the text that appears in the Variable field, and paste it into one of the template fields.
    For example, From Name: $user.full_name; From Email Address: $user.full_name; Subject: $user.company.

Specifying Template Content

Basic Information
  • Template Name - The name that appears in the list of templates.
  • Type - When this field is present, it is possible to specify multiple template types, which determines where it can be used and which template variables are available.
  • From Name - The name that indicates the person or department the email came from. For example, "Company Support".
  • From Address - The email address that end-user replies will go to. (See the note below)
  • Subject - Subject for the message.
  • Message - Choose how you want to compose the message:
  • Use the WYSIWYG HTML Editor
  • Paste HTML code written in an external editor into the RAW HTML window
  • Write a Plain Text message
Attachments

Choose one or more of the Document Templates you've created to encapsulate Case data. The document is generated from the data and attached to the message.

Notepad.png

Note:

  1. It is not possible to choose a Document Template that is based on a JSP page.
  2. You may expect a delay in receiving an email when you include attachments (File Field, Image Field, and Document Template).
Learn more: JSP Attachment Deprecation

Adding an Image

In HTML, an image is referenced using a tag that has the form: <img src="...">, where the src attribute contains the path to the image. That path must be a URL of the form http://....

Insert the URL into an <img src="..."> tag. The result is a tag of the form <img src="{imageURL}/...">.

Processing Related Records

About Related Record Variables

In a Custom Object, fields from related records can be added to a Document Template. (That is, records from an Object that has a Lookup to the current object.)

For example, OrderItems has a lookup to Orders, so in a Document Template for Orders, related OrderItems records can be accessed. (In an object Form, related records are typically displayed in a Subform, although they need not be.)

When formatting a record in the current object for printing, those related records and the fields they contain can be processed in a loop.

Finding Related-Record Variables

Related Object variables are found using the Template Variable Tool.

Here, in the Email Template for Claims, the related ClaimItems object is being chosen from the category list:

TemplateVariableToolRelatedObjects.png

Within that group, the Item Name field is listed, along with other fields in the ClaimITems object. Once selected, the variable name appears in the Variable area, along with the loop it needs to be surrounded by for processing:

#foreach( $ClaimItems_record in $ClaimItems ) $ClaimItems_record.item_name #end

If a loop already exists, you would use only the variable name part:

$ClaimItems_record.item_name

Notepad.png

Note:
For a many-to-many relationship like one between Claims and Tags, the variable looks like this:

$Claims_Tags_record.related_to_Tags.tag_name

where:

  • $Claims_Tags is the Junction Object that produces the many-to-many relationship
  • related_to_Tags is the name of the Lookup field in the Junction Object that references a Tags record
  • tag_name is the field to display
  • The "dot" separator (.) joins each of the segments in the variable name

Using Related Record Variables

Processing Related Records in a Loop

Typically, you'll create a table for the related records, define its headings, and then create a row for a single record, putting the related-record variables into the cells of the row. You then enclose that row in a loop, using the #foreach instruction defined by the Velocity templating engine.

Related records are returned in an array, so the loop creates a new table row for each record in the array.

Here is an example that processes OrderItems for an Order (with formatting attributes removed for simplicity):

<syntaxhighlight lang="xml" enclose="div">
<tbody> </tbody>
  1. foreach( $OrderItems_record in $OrderItems )
  1. end
...
Quantity Product Unit Price Amount
$OrderItems_record.item_quantity $OrderItems_record.related_to_ProductInventory.product_name $OrderItems_record.item_price $OrderItems_record.total

</syntaxhighlight>

where:

  • The <tbody> element is required around the header row.
  • The Velocity #foreach directive does the looping.
Learn more: http://velocity.apache.org/engine/releases/velocity-1.7/user-guide.html
  • The looping construct defines $OrderItems_record as a loop variable.
  • The loop variable iterates over the $OrderItems array.
  • The $OrderItems array is automatically available in the template, because OrderItems is a Related Object. (All related objects are available. Each is an array.)

Special Considerations for Subform Variables

Totals and additional computation fields defined for a Subform are also available in the Template Variable Tool. To find them, you access the main object (not the object displayed in the Subform), because those fields are added to the object that contains the Subform.

For example, the Subform for OrderItems totals the $Amount column, and then does additional computations on it to add a surcharge. Those values are shown in the $Orders Fields category as Total $Amount and Shipping for $Amount, respectively. (The final total is shown as Net Total $Amount.)

Sample Template for an Order Invoice

This sample:

  • Creates an invoice for an order, showing all items in it
  • Gets the name and price of order items from the ProductInventory object
  • Uses Velocity #foreach processing to process OrderItems records for an Order
  • Uses Velocity #if conditionals to display surcharge and discount rows only if those values are present
<syntaxhighlight lang="xml" enclose="div">

<html><head> <title></title> <style>

div {  
     padding-top: 5px;  
     padding-bottom: 5px;  
     padding-right: 5px;  
     padding-left: 30px;  
     border: 3px;  

margin-top: 5%; margin-right: 40%; margin-bottom: 5%; margin-left: 5%;

   }

</style>

</head><body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">

<img width="100" height="100" src="http://justanothermobilemonday.com/Wordpress/wp-content/uploads/2009/10/android-robot-logo2.jpg" alt="Company logo" />    <---- Company Logo Here
$company.name

$company.street  
$company.city, $company.state,
$company.country - $company.zip

 
 (Phone): $user.phone



Order Invoice

Invoice Date: $Orders.date_created



Bill To:
$Orders.account.name - $Orders.account.number

$Orders.account.street
$Orders.account.city, $Orders.account.state,
$Orders.account.country - $Orders.account.zip

(Phone): $Orders.account.phone


Invoice #: $Orders.order_number
 

<tbody> </tbody>
  1. foreach( $OrderItems_record in $OrderItems )
  1. end
  1. if( $Orders.grid_surcharge_031f67dd4b3946949df2da276e5c82a6 > 0 )
  1. end
  1. if( $Orders.grid_discount_031f67dd4b3946949df2da276e5c82a6 > 0 )
  1. end
Quantity Product Unit Price Amount
$OrderItems_record.item_quantity $OrderItems_record.related_to_ProductInventory.product_name $OrderItems_record.item_price $OrderItems_record.total
  Sub Total $Order.grid_comptn_f5631e34b39f4ba39a98559c7215a3b4
  Surcharge $Orders.grid_surcharge_f5631e34b39f4ba39a98559c7215a3b4
  Discount $Orders.grid_discount_f5631e34b39f4ba39a98559c7215a3b4
  Tax $Orders.grid_tax_f5631e34b39f4ba39a98559c7215a3b4
  Shipping $Orders.grid_shipping_f5631e34b39f4ba39a98559c7215a3b4
  TOTAL AMOUNT DUE $Orders.grid_net_total_f5631e34b39f4ba39a98559c7215a3b4



Payment Due upon reciept
Thank you for your business!

</body> </html> </syntaxhighlight>

The Subform part of the resulting invoice then looks something like this:

OrderInvoiceSampleSegment.png

(The Order Invoice Template file is available in the downloads area.)