The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Email Approval Links with an Image

Makosko
Tera Expert

Hello Gurus,

I am looking to replace standard email link text ( e.g.: click here to approve RITM00033 ) with an image ( something like thumbs up for approve and thumbs down for reject ).

I`ve modified the original mailto.approval email template so that it includes an image tag as follows: <img src="/thumbs_up.pngx" width="100" height="100" />

The problem is that SN escapes HTML tags, essentially turning my image into a text.

Is there any way to tell SN not to escape HTML ?

Thanks a lot ! ( Please see attachments for more info)

20 REPLIES 20

Maros,


That is the perfect solution and a simple way to do it.


Does not complicate the Notification and the template as well.



Thanks,


Kuldeep


Hi Kuldeep,

 

Hi tried with your following suggestions. It's working fine.

<a href="mailto:instance-name@service-now.com?Subject=Re:${number}%20-%20Approved&body=Approved">

 

<img src="/thumbs_up.pngx" width="100" height="100" onclick="target=${sys_id}"/> </img>

 

</a>

Thanks for the suggestion.

 

Could you please help me in the following requirment.

We had an image to view the current record. But I got stucked with the "href" part to view the record. So kindly help me in fixing this. I tried by calling the mail script, but it is not working.

Below is the html part and mail script described below:

<a href = ${mail_Script:view_record}>

 

<img src="/xyz" alt="View the record" width="100" height="100"/> </img>

 

</a>

 

Mail script: view_record

 

template.print("\n");
var gr = new GlideRecord('task');
gr.addQuery('sys_id',current.sysapproval);
gr.query();
while(gr.next()){
var link = new GlideSubstituteURL().generateURL(gr,'');
var title = '<p><font size="2" face="tahoma,arial,helvetica,sans-serif">Click here to <b>view'+"&nbsp;"+gr.sys_class_name.getDisplayValue()+'</b></font></p>';
var anchor = "<a href='" + link +"' > " + title +"</a>";
template.print (anchor);
}

 

 

russell_miller
Kilo Guru

Hi,



Been doing it this way for a while...



Service-now Test Dummy: Graphic Buttons for email approvals



Hope that is of use.



Cheers


R


Russell.



I do like your approach as it is more flexible than my improved business rule shown below:



(function() {


      var body = current.body.toString(),


              replace = function(txt, pat, isImage) {


                      var match;


                      while (match = pat.exec(txt)) {


                              if (isImage) {


                                  txt = txt.replace(match[0], '<img src="' + (gs.getProperty('glide.servlet.uri') + match[1]) + '" width="100" height="100" />');


                              } else {


                                  txt = txt.replace(match[0], GlideStringUtil.unEscapeHTML(match[1]));


                              }


                      }


                      return txt;


              }



      body = replace(body, /CRImage:([^\^EQ]+)?\^EQ/gm, true);


      body = replace(body, /CRText:([^\^EQ]+)?\^EQ/gm);



      current.body = body;



})()



and then in my email template, I would have the following: CRImage:thumbs_down.pngx^EQCRText:<br />Reject^EQ


basically, a link to an image + some text to accompany it..



Anyway, thanks for posting your solution. I am sure I will take advantage of it at some point in the future..


katherinelewis1
Tera Contributor

Fuji has out-of-box support for embedding images in notifications. However, the mailto templates don't seem to support any additional markup to include them.



My approach is two Notification Email Scripts; one for Approve, and one for Reject. Then for all templates on the Approver [sysapproval_approver] table, I replace any occurrence of ${mailto:mailto.approval} with ${mail_script:my_mailto_approval}, and ${mailto:mailto.rejection} with ${mail_script:my_mailto_rejection}.



my_mailto_approval:


(function(smtpAddress, approvalFor, watermark) {


      var href = 'href="mailto:'+ smtpAddress +'?subject=Re%3A%20'+ approvalFor +'%20-%20approve&amp;body='+ watermark +'"';


      var anchor = '<a '+ href +'><img src="/approve-64.pngx" style="width:64;height:64" alt="Approve" /></a>';


      template.print(anchor);


})(gs.getProperty('glide.email.user'), current.sysapproval.getDisplayValue(), email.watermark);



my_mailto_rejection:


(function(smtpAddress, approvalFor, watermark) {


      var href = 'href="mailto:'+ smtpAddress +'?subject=Re%3A%20'+ approvalFor +'%20-%20reject&amp;body='+ watermark +'"';


      var anchor = '<a '+ href +'><img src="/reject-64.pngx" style="width:64;height:64" alt="Reject" /></a>';


      template.print(anchor);


})(gs.getProperty('glide.email.user'), current.sysapproval.getDisplayValue(), email.watermark);



Of course you'll need to modify the image file names to suit your specific configuration.