Approval Email Mailto Image Links

///Approval Email Mailto Image Links

Approval Email Mailto Image Links

Last day at Knowledge11! What a great conference! I’ve had a great time meeting with so many awesome people this week. Yesterday Ian Broz and I were helping Karen Lazarenko during a 1-on-1 (maybe 2-on-1 in this case) session. She had a cool idea to make approval request emails coming from her system a little bit more intuitive by replacing or modifying the ‘mailto’ reply text links for approval and rejection with images that more clearly distinguished the links and the purpose of the email.

The challenge that we faced was how to easily add those images while maintaining the mailto functionality and populating the correct information (including the watermark ID) on the reply email. Here’s a screenshot of the solution we came up with. Read on to see how we did it!

Approval Email Images

This post is not intended to be a full explanation of the approval email notification process but I think a short explanation is helpful in understanding the problem we faced. When an approval record is put into a requested state, it triggers an event that sends out an approval email corresponding with the task the approval is associated with. The approval email (and corresponding email template) are chosen based on the task type and event triggered. For request tickets the email template is called ‘request.itil.approve.role’ and everything else uses the ‘change.itil.approve.role’ email template.

Approval templates actually go one step further by including special mailto links within the email that allow you to show ‘Approve’ and ‘Reject’ reply links directly in the email. This makes it a little bit easier for your users to process these approvals directly from their email client. The template code that does this looks like this…

${mailto:mailto.approval}

What this says is that the system will construct a mailto reply link in the email based on the ‘mailto.approval’ email template. The ‘mailto.rejection’ template serves the same purpose. Each of these two templates contains the actual text for the mailto link that pulls in the number of the task to be approved as part of the link.

Click here to approve ${sysapproval}

The end result of this setup is an email notification with a couple of links for users to approve or reject directly from their email client.

Approval Email

So…now to add images. One idea would be to modify the template code to accomplish this. The challenge is that the ‘${mailto:mailto.approval}’ command in our first template automatically adds some important information (our reply watermark ID) to the reply email for us and there’s not another simple way to replace that functionality. The simplest solution in this case was to intercept the email on its way out of the system (after the original mailto link had been formatted) and modify that piece of HTML to include our image tags. This technique is something I’ve described before on this blog if you want to read more.

All of this can be done in a simple business rule on the ‘sys_email’ table. The business rule runs when the email record is being sent and corresponds with the approval table. Then it looks for some specific text that is included only in the approval templates…’Click here to approve’ and ‘Click here to reject’, and replaces it with an image tag. The only thing you’ll need to modify in the script below are the URLs for the images themselves to point to your own instance or other publicly-available images of your choosing.

‘Add approval images’ Business Rule
Name: Add approval images
Table: Email (sys_email)
When: Before
Insert: True
Condition: current.target_table == ‘sysapproval_approver’ && current.type == ‘send-ready’
Script:

current.body = current.body.replace('Click here to approve', '<img src="https://demo.service-now.com/images/workflow_approved.gif" />');
current.body = current.body.replace('Click here to reject', '<img src="https://demo.service-now.com/images/workflow_approval_rejected.gif" />');

Here is the end result…

Approval Email Images

By | 2018-07-09T15:09:46+00:00 May 19th, 2011|Categories: Email Notifications|Tags: , , |17 Comments

About the Author:

Mark has worked in the IT industry since 2002 and with ServiceNow since 2007. He is the founder and creator of SN | Guru and the co-founder of Crossfuze, one of the worlds leading ServiceNow consulting partners. Prior to co-founding Crossfuze, he worked for ServiceNow as a Senior Architect on the Professional Services team. He has personally led dozens of successful implementations encompassing every part of the ServiceNow platform. He is also responsible for designing and developing groundbreaking ServiceNow solutions and best practices in the form of various applications, turnkey solutions, and integrations during his tenure at ServiceNow, Crossfuze and, of course, SN | Guru. These solutions are used today by ServiceNow administrators and consultants alike in hundreds of ServiceNow instances around the world!

17 Comments

  1. Andrew Wilmut May 19, 2011 at 2:43 am - Reply

    What does this look like on mobile devices? We have Droids, iPhones and Windows Mobile devices. I don’t expect it to look any different but were there any issues with formatting?

    • Mark Stanger May 19, 2011 at 4:08 am - Reply

      As long as the device can display html email it should look just fine. I just tested on an iPhone and it looks great.

  2. Dhanraj Poojari September 20, 2011 at 8:44 am - Reply

    Hello Mark, Is it possible to automate the part where the email client opens up and the approver needs to type in approve or reject in the reply email? On hitting the button can the email client directly send out an approve email.

    • Mark Stanger September 20, 2011 at 3:15 pm - Reply

      I don’t think so, but it would probably be the email client that would determine whether or not that would be possible.

      • Ganesh G October 31, 2012 at 5:34 am - Reply

        HI Mark,
        is it possible to provide an Approve or Reject button in the email notification itself and whether the below steps to can be configured in ServiceNow?
        1) Approver will get an email notification with an Approve or Reject button in the email
        2) Approver will click on Approve
        3) He will provide his comment for approval
        4) He will get an option say Save or Submit
        5) If its approved, update the request state to Approved else If its Rejected, update the request state to Rejected

        I am new to ServiceNow and don’t have that much idea about ServiceNow customization, can you please let me know the steps to achieve this.
        Any kind of help on this will help me to configure it.

        Thanks in advance.

        Thanks & Regards,
        Ganesh

        • Mark Stanger October 31, 2012 at 4:51 pm - Reply

          You can accomplish all of that with standard approval email notifications and the script here. If you’ve got other questions about email notifications or approvals you can ask them on the ServiceNow forums.

  3. Joe February 26, 2012 at 6:09 pm - Reply

    Hi Mark,

    I’m interested in using something similar for the Resolved notifications that we use for a 2 stage closure.
    Should I just be able to change the table in the business rule condition to ‘task’ (as we send out these notifications when INC’s & REQ’s are Resolved/Completed), or do I need to specify ‘task.caller’ like you have with the sysapproval_approver in the line “current.target_table == ‘sysapproval_approver’ ” ?

    Thanks,
    Joe

    • Mark Stanger February 27, 2012 at 5:31 am - Reply

      Sounds like you may need some additional help on email notifications from the forums on this one. Where you place the logic depends on whether or not you’re using ‘mailto’ links in your email that contain specific watermarks. If you want your emails to function just like this one, then you would probably want a notification going out from both the incident and the request tables. Each of these notifications would use a ‘mailto’ template like the approval emails do. Then you would need a separate business rule on the ‘sys_email’ table to find and replace the links with image links. This probably isn’t something that I can spend a significant amount of time here helping you troubleshoot so you’ll need to ask on the ServiceNow forums if you have further questions.

  4. Namrata June 18, 2012 at 2:48 am - Reply

    Hi Mark,

    I have a requirement in which i need to make sure that when approval is triggered certain fields are mandatory……

    My problem is that we have enabled mail facility where user can approve the request via email as well…..

    So is it possible to restrict the user from approving the request via email only for particular type of request…..

    Thanks in advance.

    Best Regards,
    Namrata Jain

    • Mark Stanger June 18, 2012 at 4:51 am - Reply

      The only way to accomplish this in a way that would make sense to an end-user is to set up a completely separate approval email notification for this particular case. Then you could update the conditions on your notifications to only send the appropriate one for each type of task/request. It might actually be necessary to go all the way back to the event triggers to control the separation there if you don’t have access to the necessary fields to define the conditions from the condition field on the email notification.

  5. Carlito January 2, 2013 at 5:37 pm - Reply

    Hi Mark,
    This is great and have applied it on our development instance. Our managers are liking it.
    However, base from your experience, does this affect network or internet traffic if we are looking at 100 average notifications everyday?
    thanks!
    Carlito

    • Mark Stanger January 2, 2013 at 5:46 pm - Reply

      That depends, of course, on the size of the images you’re including. Unless you’re including massive images in your emails then it shouldn’t impact it at all. Most email signatures have images in them anyway so these images should be just fine.

      • Carlito January 3, 2013 at 7:01 pm - Reply

        Is it possible to embed the images to the email itself? Seems that by default Microsoft outlook is blocking downloading of HTML contents. thanks! again.

        • Mark Stanger January 3, 2013 at 8:41 pm - Reply

          I don’t know of a simple way to do that currently.

  6. Mayank July 16, 2014 at 9:17 am - Reply

    Hi Mark,

    Thank you for this post. We are have the similar process for approval emails in which user gets an email asking to approve/reject certain request.

    To make the approval sequence more user friendly. we want to implement a functionality where user should just click on approve/reject link/image and it should automatically updates the back-end system by recording the approver’s response.
    Do you know which email clients can support this functionality? Our users use all kinds of clients including mobile(android, iOS, Symbian, etc).

    Thanks,
    Mayank

    • Mark Stanger July 16, 2014 at 9:37 am - Reply

      You’re welcome. The email client is only going to be able to do a couple of things for you. The first is to send a reply email (which is what the current setup does). The second is to provide a link to the system that, when clicked, will open up a portal and take some action in a browser window. At that point, you could authenticate the user and approve, but that’s not much different from just taking them to the approval page as we do currently.

      Another problem with that type of setup is that you don’t get any comments about the approval. If a user rejects, it’s important for them to explain why so that the requestor can take the appropriate action. You need to supply comments (in the email or in the web portal) for that to happen.

  7. Hema September 8, 2015 at 1:39 am - Reply

    Hi Mark,

    In our notifications sent out for Incident Assigned to some user, the notification subject and the body has the Incident number.
    When the Incident Number in the subject is clicked, it goes to the corresponding record. For some cases, the subject as well as body is showing a wrong Incident Number and If clicked on, its taking us to the correct Record. If i try to search the displayed Number in the Global Search, Its throwing error that the number doesn’t exists.
    Could you please help me with this issue.

    Thanks,
    Hema

Leave A Comment