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!
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…
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.
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.
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.
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 reject', '<img src="https://demo.service-now.com/images/workflow_approval_rejected.gif" />');
Here is the end result…
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?
As long as the device can display html email it should look just fine. I just tested on an iPhone and it looks great.
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.
I don’t think so, but it would probably be the email client that would determine whether or not that would be possible.
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
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.
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
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.
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
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.
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
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.
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.
I don’t know of a simple way to do that currently.
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
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.
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