One topic for which CorasWorks Support receives a number of calls is the Optional Email Process. As described in the List Item Emailer Wizard Properties, this allows you to define different emails to be sent based upon the value in a particular column of the email-enabled list. It directs the List Item Emailer web part to look at the value in the identified column and, based on that value, send the appropriate email message to the identified recipients.
NOTE: With the Optional Email Process, emails will be sent only when the individual list item is opened and then closed. Emails will not be sent based on a filter (e.g., Due Date) if the item has not been opened, or if the item is opened and closed in Datasheet mode.
This topic provides the code for a series of messages to be sent based upon the values within the Status column of a task list. A different message will be sent to the appropriate audience for each possible value. The messages will be formatted using HTML, including code for using a table to format the data. Of course, you can customize this example to fit your needs and the steps in your processes.
There will be a total of five steps to the process, one for each Status type, as defined in the table below. This table shows the values and title of each message to be defined.
Status Value |
Message Sent To |
Title of Notification |
Not Started |
To: Assigned To CC: Person Creating Task |
Task has been Assigned |
In Progress |
To: Assigned To CC: manager@abc.com |
Task has been Started |
Completed |
To: Assigned To CC: Person Creating Task |
Task has been Completed |
Deferred |
To: Person Creating Task CC: manager@abc.com |
Warning Task has been Deferred |
Waiting on Someone Else |
To: Person Creating Task CC: Assigned To |
Warning Task is Waiting on Someone Else |
You can start with the code for the Not Started message:
Status#;Not
Started#;Assigned To#;Created By#;Created By#;Task has been Assigned#;The
following task has been assigned to you.<br>
<table border=1
width=100%>
<tr> <td width=111><b><font
face=Arial size=2>Task
Title</font></b></td><td><*=Title*></td>
</tr>
<tr> <td width=111><b><font face=Arial
size=2>Assigned
To</font></b></td><td><*=Assigned To*></td>
</tr>
<tr> <td width=111><b><font face=Arial
size=2>Description</font></b></td><td><*=Description*></td>
</tr>
<tr> <td width=111><b><font face=Arial
size=2>Due Date</font></b></td><td><*=Due
Date*></td> </tr>
<tr> <td
width=111><b><font face=Arial size=2>Task
Link</font></b></td><td><a
href=<*=ItemURL*>>Click Here</a></td>
</tr>
</table>
Look at this code before you go any further to make sure you understand what it is doing. As is stated in the List Item Emailer Wizard Properties topic, the format for each entry in the Optional Email Process is:
Field#;Value#;Email To#;CC#;Email From#;Subject#;Body
So, if you look at the sample code above, it can be broken down as described here:
Parameter |
Usage |
Value in Process |
Field |
Column name referenced by the process |
Status |
Value |
Value within column |
Not Started |
Email To |
Destination of the notification |
Assigned To |
CC |
Another address |
Created By |
Email From |
Source of email |
Created By |
Subject |
Title of email message |
Task has been Assigned |
Body |
Format of email body |
HTML-encoded body with column values |
This process looks at the Status column. When the Status is set to Not Started, a notification message will be sent with the following settings:
· It will be sent to the value within the Assigned To column
· A copy will be sent to the address found within the Created By column
· The Created By person will also be listed as the originator of the message
· The title of the message is Task has been Assigned
The body of the email is HTML-encoded, using a table with rows and cells. Within the cells are text and the values from the identified columns. So the body of the message includes:
· Line of Greeting: The following task has been assigned to you. <br>
· Starting of an HTML table: <table border=1 width=100%>
· Creating of Rows and Cells: <tr> <td width=111> </td> </tr>
· Value Identifiers: <font face=Arial size=2>Task Title</font>
· Column Values: <*=Description*>
The message that is sent has the formatting of a table that includes the values of the columns. It is not required that the notification be formatted using HTML code, but the resulting notification is placed within a table and is easy to read.
Now, you can easily add the code for the remaining steps in the process (the other possible status values) by copying, pasting, and modifying the sample code above.
If you want to start with the sample code provided above for the Not Started, you can copy and paste it for each step in the process. If you have your own code, copy and paste that. Make sure you type <NEW> at the end of each process. So you would copy the first set of code, type <NEW>, and then paste and make the necessary modifications to the status, destinations, title, and body. Then repeat.
For the example described above, the final code looks like this. As the task moves along through each status, a different message is sent.
Status#;Not
Started#;Assigned To#;Created By#;Created By#;Task has been Assigned#;The
following task has been assigned to you.<br>
<table border=1
width=100%>
<tr> <td width=111><b><font
face=Arial size=2>Task
Title</font></b></td><td><*=Title*></td>
</tr>
<tr> <td width=111><b><font face=Arial
size=2>Assigned
To</font></b></td><td><*=Assigned To*></td>
</tr>
<tr> <td width=111><b><font face=Arial
size=2>Description</font></b></td><td><*=Description*></td>
</tr>
<tr> <td width=111><b><font face=Arial
size=2>Due Date</font></b></td><td><*=Due
Date*></td> </tr>
<tr> <td
width=111><b><font face=Arial size=2>Task
Link</font></b></td><td><a
href=<*=ItemURL*>>Click Here</a></td>
</tr>
</table>
<NEW>
Status#;In Progress#;Assigned
To#;manager@abc.com#;Created By#;Task has been Started#;The following task has
been started.<br>
<table border=1 width=100%>
<tr>
<td width=111><b><font face=Arial size=2>Task
Title</font></b></td><td><*=Title*></td>
</tr>
<tr> <td width=111><b><font face=Arial
size=2>Assigned
To</font></b></td><td><*=Assigned To*></td>
</tr>
<tr> <td width=111><b><font face=Arial
size=2>Description</font></b></td><td><*=Description*></td>
</tr>
<tr> <td width=111><b><font face=Arial
size=2>Due Date</font></b></td><td><*=Due
Date*></td> </tr>
<tr> <td
width=111><b><font face=Arial size=2>Task
Link</font></b></td><td><a
href=<*=ItemURL*>>Click Here</a></td>
</tr>
</table>
<NEW>
Status#;Completed#;Assigned
To#;Created By#;Created By#;Task has been Completed#;The following task has been
completed.<br>
<table border=1 width=100%>
<tr>
<td width=111><b><font face=Arial size=2>Task
Title</font></b></td><td><*=Title*></td>
</tr>
<tr> <td width=111><b><font face=Arial
size=2>Assigned
To</font></b></td><td><*=Assigned To*></td>
</tr>
<tr> <td width=111><b><font face=Arial
size=2>Description</font></b></td><td><*=Description*></td>
</tr>
<tr> <td width=111><b><font face=Arial
size=2>Due Date</font></b></td><td><*=Due
Date*></td> </tr>
<tr> <td
width=111><b><font face=Arial size=2>Task
Link</font></b></td><td><a
href=<*=ItemURL*>>Click Here</a></td>
</tr>
</table>
<NEW>
Status#;Deferred#;Created
By#;manager@abc.com#;Created By#;Warning - Task has been Deferred#;The following
task has been deferred.<br>
<table border=1
width=100%>
<tr> <td width=111><b><font
face=Arial size=2>Task
Title</font></b></td><td><*=Title*></td>
</tr>
<tr> <td width=111><b><font face=Arial
size=2>Assigned
To</font></b></td><td><*=Assigned To*></td>
</tr>
<tr> <td width=111><b><font face=Arial
size=2>Description</font></b></td><td><*=Description*></td>
</tr>
<tr> <td width=111><b><font face=Arial
size=2>Due Date</font></b></td><td><*=Due
Date*></td> </tr>
<tr> <td
width=111><b><font face=Arial size=2>Task
Link</font></b></td><td><a
href=<*=ItemURL*>>Click Here</a></td>
</tr>
</table>
<NEW>
Status#;Waiting on Someone
Else#;Created By#;Assigned To#;Created By#;Warning - Task is Waiting on Someone
Else#;The following task is waiting on someone else.<br>
<table
border=1 width=100%>
<tr> <td
width=111><b><font face=Arial size=2>Task
Title</font></b></td><td><*=Title*></td>
</tr>
<tr> <td width=111><b><font face=Arial
size=2>Assigned
To</font></b></td><td><*=Assigned To*></td>
</tr>
<tr> <td width=111><b><font face=Arial
size=2>Description</font></b></td><td><*=Description*></td>
</tr>
<tr> <td width=111><b><font face=Arial
size=2>Due Date</font></b></td><td><*=Due
Date*></td> </tr>
<tr> <td
width=111><b><font face=Arial size=2>Task
Link</font></b></td><td><a
href=<*=ItemURL*>>Click Here</a></td>
</tr>
</table>