Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Need to create email notification

Pooja Khatri
Tera Contributor

Hi All ,

 

I am trying to create an email notification using an Email script and also script include 

I am trying to include the fields short description , description  etc one above the other like the below :

 

PoojaKhatri_0-1697633680706.png

 

I am using the below email script which I am using for the hyperlinks and having the above mentioned format for the entered dataa

 

Script : 

 

(function runMailScript(current, template, email, email_action, event) {

try{

 

var task = current.sysapproval;

var class_name = task.sys_class_name.toString();

var content = new NonBatchNotificationContentnormalchange('sysapproval_approver').content;

var emailSub="";

//----------------------------------------------- Build Subject ----------------------------------------------

emailSub="change approval for "+task.number;

email.setSubject(emailSub);

 

//----------------------------------------------- Begin Build Body --------------------------------------------

var format = new EVG_EmailFormatter('IT_Outlook');

var body = "";

 

body += format.getSection('begin', {});

 

//----------------------------------------------- Add URL ----------------------------------------------------

body += format.getSection('url_section',{

'URL': gs.getProperty('glide.servlet.uri') + "nav_to.do?uri=" + GlideStringUtil.urlEncode(gs.generateURL(current.getTableName(), current.sys_id)),

'CLICK_TEXT': "Click here to view Request"

});

 

body += format.getSection('url_section',{

'URL': gs.getProperty('glide.servlet.uri') + "nav_to.do?uri=" + GlideStringUtil.urlEncode(gs.generateURL(class_name, task.sys_id)),

'CLICK_TEXT': "Click here to view " + task.number

});

 

//----------------------------------------------- Content Section --------------------------------------------

//format content fields into the email

body += format.getSection('begin_content_section', {});

for(var c in content.fields){

body += format.getSection('add_two_field_content_row',{

'FIELD': content.fields[c].field,

'CONTENT': content.fields[c].value

});

}

body += format.getSection('end_content_section_row', {});

body += format.getSection('add_description_row',{

'DESCRIPTION': task.description.toString().replace(/\n/g, "<br />")

});

body += format.getSection('end_content_section', {});

 

//----------------------------------------------- Approve or Reject ----------------------------------------------------

var apprv = "mailto:" + gs.getProperty('glide.email.user') + "?subject=Re:" + task.number + " - approve&body=" + email.watermark;

var rej = "mailto:" + gs.getProperty('glide.email.user') + "?subject=Re:" + task.number + " - reject&body=" + email.watermark;

body += "<tr style=\"padding-top:10px;padding-bottom:10px;\"><td width=\"100%\" style='width:100.0%;padding:0in 5.4pt 0in 5.4pt;padding-bottom:15px;'> <p class=MsoNormal align=center style='mso-margin-top-alt:auto;mso-margin-bottom-alt: auto;text-align:center'> <span style='font-size:12.0pt; color:black'></span> <span style='font-family:\"Helvetica\",sans-serif;font-size:12.0pt'> <a href=\"mailto:" + gs.getProperty('glide.email.user') + "?subject=Re:" + task.number + " - approve&body=" + email.watermark + "\">Approve</a> | <a href=\"mailto:" + gs.getProperty('glide.email.user') + "?subject=Re:" + task.number + " - reject&body=" + email.watermark + "\">Reject</a>  </span> </p> </td></tr>";

 

//----------------------------------------------- Set the Body ---------------------------------------------

body += format.getSection('end', {});

email.setBody(body);

 

//----------------------------------------------- If Error Thrown ----------------------------------------------

}catch(error_msg){

gs.log('Body Error - ' + error_msg, email_action.name);

}

})(current, template, email, email_action, event);

 

 

and in the below Script include I am setting up the above mentioned fields 

 

var NCR = Class.create();
NCR.prototype = {
    initialize: function(class_name) {
 
var task = new GlideRecord('task');
 
if(class_name == 'sysapproval_approver'){
task = current.sysapproval;
}
else{
task = current;
}
var task_class_name = task.sys_class_name.toString();
if(task_class_name == 'change_request') { 
this.content = {
fields: [
{field: "Short Description", value: task.short_description.getDisplayValue()},
{field: "Change Coordinator", value: task.requested_by.getDisplayValue()},
{field: "Change Type", value: task.type.getDisplayValue()}, 
{field: "Configuration Item", value: task.cmdb_ci.getDisplayValue()}, 
{field: "Category", value: task.u_category.getDisplayValue()},
{field: "Hosting Impact", value: (task.u_hosting_impact) ? "true" : "false"},
{field: "Probability", value: task.u_probability.getDisplayValue()},
{field: "Risk", value: task.risk.getDisplayValue()},
{field: "Impact", value: task.impact.getDisplayValue()},
{field: "TWM", value: (task.u_third_weekend_maintenance) ? "true" : "false"},
{field: "Planned start date", value: (task.start_date.nil()) ? "" : this.getEST(task.start_date)},
{field: "Planned end date", value: (task.end_date.nil()) ? "" : this.getEST(task.end_date)}
]
};
}
},
getEST : function(time){
var tz = Packages.java.util.TimeZone.getTimeZone("US"); 
var GDT = new GlideDateTime(time); 
GDT.setTZ(tz);
return GDT.getDisplayValueInternal() + ' EST';
},
    type: 'NCR'
};
 
But I am unable to get the below above mentioned fields in a single column one below the other , can someone help me to fix it ?
0 REPLIES 0