[+]
[+]
[-]
 [+]
  
 [+]
 [+]
  
 [+]
 [+]
 [+]
 [+]
 [+]
 [+]
 [+]
 [-]
  [+]
   
   
   
  [+]
   
  [-]
    
    
    
 [+]
 [+]
[+]
Updated on 12/10/2019
Workflow Documentation
Email Template Control Flow Statements
Direct link to topic in this publication:

PREVIOUS  |  NEXT

Email Template Control Flow Statements

Quick Links


Workflow enables you to add these control flow statements to email templates:

  • #if / #else: Enables you to evaluate a condition and then apply an action based on the result.
  • #elseIf: Supports the evaluation of two or more conditions in the same action, and enables you to apply an action based on the results of the evaluation.
  • #foreach: Enables you to evaluate a list of elements and then apply an action to a specific element.  
  • #parse: Enables you to include content from another template. 
  • #set: Enables you to read all variables from a set or sets of input data.

#if / #else Statements

[Back to top]


The #if/#else statement is a powerful way to evaluate conditions and then apply actions depending on the results of the evaluation.

The following is the basic syntax: 

#if (yourCondition)
     if the condition is true, display XYZ
#else
     if the condition is false, display ABC 
#end  


Important: It is important that you always include #end  at the end of your #if / #else ,  #elseIf , and #foreach statements.

Example: You can use the #if/#else statement to evaluate an Assign action. In this example, we want to evaluate when the case is in one specific status (Inspect) and in a specific workflow (Merchandise Returns). When the condition is true, we want to display a specific message. When the condition is false, we want to display a different message. The code will look something like this:

#if (${case.caseType.name} == 'Merchandise Returns' && ${case.status.name} == 'Inspect')
     The returned merchandise has been received. Please inspect the items.
#else
     User1 assigned the case to User2.
#end


#elseif Statements

[Back to top]

The #elseif statement enables you to evaluate for two or more conditions on the same action, and then apply actions based on the results of the evaluation.

The following is the basic syntax:

#if (firstCondition)
     if the first condition is true, display XXX message
#elseif (secondCondition)
     if the first condition is false and the second condition is true, display YYY message 
#else
     if both conditions are false, display ZZZ message
#end  


Example
: Similar to the #if/#else example, we will evaluate the workflow and specific statuses of a case on an Assign action.  On evaluation, we will display a different message depending on which statuses a case is in. If either of the first two conditions are true, we will display the corresponding message. When the first two conditions return false, we will display the corresponding message. Your code will look something like this:

#if (${case.caseType.name} == 'Merchandise Returns' && ${case.status.name} == 'Inspect')
     The returned merchandise has been received. Please inspect the items.
#elseif (${case.caseType.name} == 'Sales Order' && ${case.status.name} == 'Prepare to Ship')
     Payment has been received for this order. Please prepare the items for shipment.
#else
     User1 assigned the case to User2.
#end   

Important: It is important that you always include #end  at the end of your #if / #else ,  #elseIf , and #foreach statements.

#foreach Statements

[Back to top]

The #foreach statement enables you to evaluate a list of elements and then perform an operation on that specific element. The following is the basic syntax:
#foreach( $comment in $case.getComments() )
    $comment.text
#end  

Important: It is important that you always include #end  at the end of your #if / #else ,  #elseIf , and #foreach statements.

#parse Statements

[Back to top]

Workflow enables you to use the #parse statement to include content from another template by including the path to the desired template. The statement will look something like this, where header.vm is the name of the desired template:

#parse("template/email/common/header.vm")


The #parse statement is useful when you have a repeating section in multiple email templates.

Example: If you use the same details in every email template, you could add the same lines of code in each template. Using the #parse statement, instead of repeating the code in every template, you could move those lines of code to a new template, such as a template named caseDetails.vm . Then, you can use the #parse statement to call that template. The code would look something like this:

#parse("template/email/common/caseDetails.vm") 


You can also use the #parse statement to include the same footer information in all your email templates. 

Example: Create a template named footer.vm and then use this statement in an email template to call the footer details: 

#parse("template/email/common/footer.vm")

#set Statements

[Back to top]

Workflow enables you to use the #set statement and reads all variables from a set of input data. A #set statement can contain multiple data sets.

#set {$variable = someValue}

Example: The following example includes #set and #foreach statements and displays the container and all of its columns, rows and values.

#set( $columns = $customTable.getTable("containerCustomFieldName").columns) 
<table>
   <tr>
      #foreach($column in $columns)
         <th>$column.name</th>
      #end   
   </tr>
#foreach($row in $customTable.getTable("containerCustomFieldName").rows)
   <tr>
      #foreach($column in $columns)
         <td>$row.getValue($column.name)</td>
      #end
   </tr>
#end