Displaying images from emails inline, not as an attachment.

richard_selby
Kilo Guru

Most of our support enquiries arrive by email, and are viewed by the support staff in the Activity Log section.
This works fine when the email is mostly plain text, bar a corporate logo. But some clients send us notifications in the form of a pretty diary of planned outages rendered by a graphic designer.
ServiceNow strips off the attachment and requires the user to click a link up the top of the screen.

Is there anyway we can get ServiceNow to display png/jpg attachments inline with the text on the activity journal?

A related problem is HTML table data in emails. All HTML is stripped. Is this configurable?

27 REPLIES 27

I have the same issues as well,. I'm using the code tag on my inbound action also.. images are shown like this on the activity logs



Capture1.JPG


amacqueen
Mega Guru

I don't know if this helps anyone but I found a scrip some time ago (can't remember where) that automatically creates a knowledge base article with in-line graphics. I'm afraid I'm not a scripting Guru but one of you may be able to adapt it?



Currently it's on the knowledge [kb_knowlege] table



Condition script - email.subject.startsWith("Knowledge")



Business Rule:-



var gdt = new GlideDate();


gdt.addDays(2);


//current.valid_to = gdt;


var desc = email.subject;


desc = desc.replace("Knowledge:","");


current.short_description = desc.trim();


current.workflow_state = "draft";


current.topic = "General";


//current.category = "";


current.roles = "knowledge";


 


 


//Find and replace the image tags with the proper source.  


//Get the number of attachments so the loop can be exited  


//so it will stop no mater what.  


var currentCount = 0;


var newBody = email.body_html;


var searchBody = email.body_html.replace(/\n/g, " ");


 


 


var regex = /<img(.*?)>/ig;


var match;


var match2;


while(match = regex.exec(searchBody)){


//Add a style float tag next to the align tag.


var alignText = match[0].replace(/align=['"]?left['"]?/gi, 'align="left" style="FLOAT: left"');


alignText = alignText.replace(/align=['"]?right['"]?/gi, 'align="right" style="FLOAT: right"');


searchBody = searchBody.replace(match[0], alignText);


var regex2 = /src=("(.)*?"|'(.)*?'|(.)*?\s+$)?/ig;


while(match2 = regex2.exec(alignText)){


findAndReplaceImage(match2[1].replace(/\s+$/,"").replace(/"+/g,"").replace(/'+/g,""));


}  


currentCount += 1;


if(currentCount >= 100)


break;  


}  


searchBody = searchBody.replace(/<o:p>(.*?)<\/o:p>/ig, "");


currentCount = 0;


var regex2 = /<!--\[if(.*?)<!\[endif\]-->/ig;


while(match = regex2.exec(searchBody)){


searchBody = searchBody.replace(match[0], "");


currentCount += 1;


if(currentCount >= 100)  


break;  


}  


currentCount = 0;  


var regex2 = /<!\[if !vml\]>(.*?)<!\[endif\]>/ig;  


while(match = regex2.exec(searchBody)){  


searchBody = searchBody.replace(match[0], match[1]);  


currentCount += 1;  


if(currentCount >= 100)  


break;  


}  


 


 


//gs.log("Create Morning Post: " + searchBody);  


 


 


current.text = searchBody;  


 


 


current.insert();  


 


 


event.state="stop_processing";  


 


 


function getEmailSYSID(emailuid) {  


var em = new GlideRecord('sys_email');  


em.addQuery('uid', emailuid);  


em.query();  


while(em.next()) {  


//we execute the return only within a certain time difference between the creation of the attachment and now (in seconds)  


var dif = gs.dateDiff(em.sys_created_on, gs.nowNoTZ(), true);  


//gs.log("difference: " + dif + "eid: " + em.sys_id + " uid: " + em.uid); //debug  


if(dif < 300 && dif > -300){  


//gs.log('passed dif if: ' + em.sys_id + " uid: " + em.uid); //debug  


return em.sys_id;  


  }  


  }  


return "";  


}  


 


 


 


function findAndReplaceImage(imageText){  


var img = imageText;  


var imgName = img.substring(4, img.search(/@/i));  


var imgCode = "sys_attachment.do?sys_id=";  


//Get the sys_id of the attachment  


var gr = new GlideRecord("sys_attachment");  


gr.addQuery("file_name", imgName);  


gr.addQuery("table_sys_id", getEmailSYSID(email.uid));  


gr.query();  


if (gr.next()) {  


imgCode += gr.sys_id;  


  }  


searchBody = searchBody.replace(img, imgCode);  


}  



Not sure how much use it is?


Thanks!



Maybe someone can help answer this. From the script, how does it know which image to replace? From what I know the attachments are not in order.



ie. if the email has 3 inline images, how does it know which one is the first, second, third?


declann
Kilo Explorer

Looks like this has been addressed in Fuji, with the new System Property: glide.email.inbound.convert_html_inline_attachment_references


http://wiki.servicenow.com/index.php?title=Available_System_Properties


Hallelujah! I see you have to add the property first.