Email script image/video ServiceNow

 


(function runMailScript(current,template,email,email_action,event) {
var u_custom_attachment = current.u_custom_attachment;
var filename = '';
var grSysAttachment = new GlideRecord('sys_attachment');
if(grSysAttachment.get(u_custom_attachment)){
filename = grSysAttachment.getValue('file_name');
}
if(filename){
var fileNameExtType = '';
if(filename){
var fileNameExt = filename.substring(filename.lastIndexOf('.')+1, filename.length) || filename;
if( fileNameExt == 'jpg' || fileNameExt == 'jpeg' || fileNameExt == 'gif' || fileNameExt == 'png'){
fileNameExtType = 'image';
}else{
fileNameExtType = 'video';
}
}
var fileUrl = '';
if(fileNameExtType == 'video'){ //Custom Video
fileUrl = gs.getProperty('glide.servlet.uri')+'/sys_attachment.do?sys_id='+u_custom_attachment;
template.print("<video style='width: 100%;' controls='controls' src='"+fileUrl+"' >");
}else{ //Custom Image
fileUrl = gs.getProperty('glide.servlet.uri')+u_custom_attachment+'.iix';
template.print("<img style='width: 100%;' src='"+fileUrl+"'>");
}
}else{ //OOB Ecard Image
fileUrl = gs.getProperty('glide.servlet.uri')+current.u_ecard.image+'.iix';
template.print("<img style='width: 100%;' src='"+fileUrl+"'>");
}
})(current, template, email, email_action, event);