HTML Emails in SDE

A lot of people ask about sending email notifications from SDE in HTML format.  This is a great way to make your notifications consistent and easy to read for your users.  It also works very well for including links in the email for your users to click.  There aren’t too many email clients that won’t display HTML emails these days, although I have in the past had slight problems with Lotus Notes where tables don’t display exactly how you expect.  It is not a show-stopper and usually can be remedied with some minor tweaking specific to the way Notes handles HTML.  Also, certain versions of BlackBerry devices do not display HTML at all, or not very well – especially HTML links.

Business Rules Templates used in conjunction with some simple HTML and Cascading Style Sheets will make the notifications look very professional and consistent.   At the end of this post I will provide some downloadable Business Rules Templates that you can use in your own rules and tweak as needed.  Let’s dive right in and get started.

The basic requirement for having emails sent by SDE display in HTML format is to include the <HTML> and </html> tags around the body of the notification.  HTML formatting in email subjects is not supported by email clients, however.  Here is an example of a simple Incident notification in HTML format:

<HTML>
Incident #{TR,Incident #} has been created for you.<BR>
<BR>
<B>Open Date & Time:</b> {TR,Open Date & Time}<BR>
<B>Category:</b> {TR,Subject Description}<BR>
<B>Urgency:</b> {TR,Urgency ID:}
</html>

Remember to always use the HTML line break tag <BR> rather than just pressing enter in the notification.

The above is a very basic example of how to use HTML in notifications.  However, what if you have multiple Incident notifications and want to use the same format in all of them?  You could put the HTML into each notification body, but then if you ever want to make changes you are stuck modifying multiple rules.   This is where Business Rules Templates come into play.  Here is the template I use at the beginning of all of my notifications – I name it _HTML_HEAD:

<HTML>
<HEAD>
<STYLE type=”text/css”>
body,table,td,th{
font-family:arial,helvetica;
font-size:10pt;
}
table,td,th{
border:1px solid #000;
border-collapse:collapse;
margin:0;
padding:0;
text-align:left;
}
td,th{
padding:.2em .5em;
vertical-align:top;
font-weight:normal;
}
tbody td{
background:#ccc;
}
tbody th{
background:#aaa;
font-size:9pt;
font-weight:bold;
}
pre{
font-family:arial,helvetica;
}
</style>
</head>
<BODY>

This provides very nice formatting for including information in a table format.  I create an _HTML_FOOT template also:

<BR><CENTER><HR width=”80%” size=”1″ noshade>
<FONT color=”silver” size=”1″>{EVENTMODULE} {EVENTMETHOD} / {RULENAME}</font>
</body>
</html>

Putting this at the end of every notification will provide you with information for troubleshooting purposes, including information about the event and Business Rule that generated the notification.  Note that the module you choose for the HTML templates does not matter.  Since no actual fields from any module are used in them, you can use them for notifications based on Incidents, Work Orders, Change Requests, and any other module.

Here is the standard Incident template I use for notifications, which I name _INCIDENT:

<TABLE width=”80%”>
<TR>
<TH width=”150″>Incident #</th>
<TD>{TR,Incident #}</td>
</tr>
<TR>
<TH>Opened</th>
<TD>{TR,Open Date & Time}</td>
</tr>
<TR>
<TH>Client</th>
<TD>{TR,Client ID} – {TR,First Name} {TR,Last Name}</td>
</tr>
<TR>
<TH>Phone</th>
<TD>{TR,Cl.Phone #}</td>
</tr>
<TR>
<TH>Email</th>
<TD>{EXTRACT,{},{TR,Client Email}}</td>
</tr>
<TR>
<TH>Company</th>
<TD>{TR,Company Name}</td>
</tr>
<TR>
<TH>Department</th>
<TD>{TR,Department Name}</td>
</tr>
<TR>
<TH>Category</th>
<TD>{TR,Subject Description}</td>
</tr>
<TR>
<TH>Urgency</th>
<TD>{TR,Urgency ID:}</td>
</tr>
<TR>
<TH>Assigned Staff</th>
<TD>{TR,Login ID Assigned To} – {TR,First Name Assigned To} {TR,Last Name Assigned To}</td>
</tr>
<TR>
<TH>Assigned Group</th>
<TD>{TR,Group Name}</td>
</tr>
<TR>
<TH colspan=”2″>Description</th>
</tr>
<TR>
<TD colspan=”2″><PRE>{TR,Incident Description}</pre></td>
</tr>
</table>

Notice I use the <TH> and <TD> table tags in conjunction with the style sheet to control the formatting.  Putting these templates together into a notification is very simple.  I usually include descriptive text unique to each rule so that the person receiving the email will understand why it was sent to them:

Incident Notification with HTML and templates

Here is how the notification looks to the person receiving it:

Incident Notification Result

With SDE’s ability to generate a link that takes a Staff member to the application and opens a particular record, it is common to include the links in email notifications.  However, you don’t want the Clients seeing these links because they won’t work.  Because of this, I create separate templates for the links.  Here is the template I use for Incident links, appropriately named _INCIDENT_LINKS:

<A HREF=”{LINK,Incident,{TR,Incident #},}”>Click here</a> to view this Incident in SDE.

This is so simple it seems like using a template for this is overkill.  Again, remember that you may include this template in many rules and if you ever want to make a change to it you’ll only have to make that change to the template.  My template _WORKORDER_LINKS also includes a link to the parent Incident (if one exists).  This is an example of the fact that MATH statements, and of course DB Lookups, can be used in templates as well.

<A HREF=”{LINK,Work Orders,{TR,Work Order #},}”>Click here</a> to view the Work Order in SDE.<BR>
{MATH,(CASE WHEN ‘{TR,Seq.HD #}’ <> ” THEN ‘<A HREF=”{LINK,Incident,{TR,Seq.HD #},}”>Click here</a> to view the parent Incident in SDE.’ ELSE ” END)}

The above template will always show a link to the Work Order, but the MATH statement will only display the link to the parent Incident if there is one.

The last aspect of templates I want to discuss is the context of the Business Rule and template.  This is very important.  As an example, suppose you want to trigger a Business Rule from the creation of an Incident Detail with a particular Action ID.  If you want to include the Incident template in a notification from this rule the problem is that you can’t just use {TR} fields from the Incident – the context of the rule is Incident Details, not Incidents.  For this reason, I create a template named _INCIDENT_LOOKUPS:

<TABLE width=”80%”>
<TR>
<TH width=”150″>Incident #</th>
<TD>{TR,Incident #}</td>
</tr>
<TR>
<TH>Opened</th>
<TD>{DB,Incident,Open Date & Time,”Incident #” = {TR,Incident #}}</td>
</tr>
<TR>
<TH>Client</th>
<TD>{DB,Incident,Client ID,”Incident #” = {TR,Incident #}} – {DB,Incident,First Name,”Incident #” = {TR,Incident #}} {DB,Incident,Last Name,”Incident #” = {TR,Incident #}}</td>
</tr>
<TR>
<TH>Phone</th>
<TD>{DB,Incident,Cl.Phone #,”Incident #” = {TR,Incident #}}</td>
</tr>
<TR>
<TH>Email</th>
<TD>{EXTRACT,{},{DB,Incident,Client Email,”Incident #” = {TR,Incident #}}}</td>
</tr>
<TR>
<TH>Company</th>
<TD>{DB,Incident,Company Name,”Incident #” = {TR,Incident #}}</td>
</tr>
<TR>
<TH>Department</th>
<TD>{DB,Incident,Department Name,”Incident #” = {TR,Incident #}}</td>
</tr>
<TR>
<TH>Category</th>
<TD>{DB,Incident,Subject Description,”Incident #” = {TR,Incident #}}</td>
</tr>
<TR>
<TH>Urgency</th>
<TD>{DB,Incident,Urgency ID:,”Incident #” = {TR,Incident #}}</td>
</tr>
<TR>
<TH>Assigned Staff</th>
<TD>{DB,Incident,Login ID Assigned To,”Incident #” = {TR,Incident #}} – {DB,Incident,First Name Assigned To,”Incident #” = {TR,Incident #}} {DB,Incident,Last Name Assigned To,”Incident #” = {TR,Incident #}}</td>
</tr>
<TR>
<TH>Assigned Group</th>
<TD>{DB,Incident,Group Name,”Incident #” = {TR,Incident #}}</td>
</tr>
<TR>
<TH colspan=”2″>Description</th>
</tr>
<TR>
<TD colspan=”2″><PRE>{DB,Incident,Incident Description,”Incident #” = {TR,Incident #}}</pre></td>
</tr>
</table>

As you can see, this template uses the Incident # to lookup all the Incident fields.  It is simply a coincidence that the foreign key in the Incident Details module is called Incident #.  This is, however, a useful coincidence.  If you are doing time-based rules where the notification is delayed, you always want to use DB Lookups to get the most current data when the notification is sent.  Since {TR,Incident #} is a valid field in the Incident module, you can use this lookup template in those notifications.

Finally, here is a link to a set of text files that contain the basic templates I like to use.   You can modify them to suit your needs, of course.  Keep in mind that in the Change Approval template I have used some fields that aren’t available in the module by default.  You’ll either have to remove them from the template, change them to DB Lookups, or add them as virtual fields to the Change Approval module (which is what I do).

Downloadable Business Rules Templates

Advertisements

13 thoughts on “HTML Emails in SDE

  1. Nice article. By the way some email clients dont like not having no form # when the link is generated with the {LINK,Incident,{TR,Seq.HD #},} syntax.
    Basicaly it will generate the following link
    http://Server/SDE/Default.asp(x)?ModSeq=24&Sequence=123&FormSeq=

    They see that FormSeq does not have a value so they do not pass this parameter at all. Well SDE does not like that parameter missing.

    To work around this you could just add an additional parameter to the end like so.
    {LINK,Incident,{TR,Seq.HD #},}&Extra=0

    http://Server/SDE/Default.asp(x)?ModSeq=24&Sequence=123&FormSeq=&Extra=0

    This will cause all parameters to be passed. But because SDE is not expecting the Extra parameter it does not even notice it is there.

    • David,

      Thanks for the tip. I haven’t run across this but I’ll definitely incorporate this into my links in the future. Another thing worth mentioning (sure you already know) is that sometimes SDE doesn’t like not having a form number and will corrupt the notification body. To work around this, generate the link manually:

      [a HREF=”http://ourserver/sde/default.asp(x)?ModSeq=24&Sequence={TR,Incident #}&FormSeq=&Extra=0″]Click here[/a] to view this Incident in SDE.

      — Paul

  2. how can i send in a notification the access to the CI module
    i try in this way
    Puedes ver mas detalle del CI aqui:
    {LINK,Inventory Items,{TR,Sequence},1005}

    {EVENTMODULE} {EVENTMETHOD} / {RULENAME}

    but i see the text in the LINK part

  3. Pingback: HTML Email Template | JOATIT
  4. Great articles. They have been very helpful and make SDE alot more pleasing to view and work with.

    Thanks for sharing your knowledge. It is much appreciated.

    My thoughts on the email notification. I am seeing being stipped out of the email notification, so any paragraphs in the Incident Description, Resolution or Notes get compacted into one long paragraph.

    Any thoughts on this?

  5. UPDATED – Edit last posting: My thoughts on the email notification. I am seeing the carriage return or break being stipped out of the email notification, so any paragraphs in the Incident Description, Resolution or Notes get compacted into one long paragraph when viewing the email notification.

  6. I had the same issue and resolved it with this:

    {TR,Incident Description}

    I had to create it it’s own class as the font was all wrong. Works like a charm now.

  7. Arg, what I am trying to say is put {TR,Incident Description} inside a pre tag with it’s own class to set the style.

    Apologies to the Site Admin for 3 posts but I’m not sure how to post on here without the tags being interpreted by your site.

  8. OUt of curiosity, how do you handle incoming html based emails? We receive some from automated services within the company, but SDE basically breaks them down into their raw html code and displays them in the incident description. Is there a way to format an incoming html email to display properly?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s