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.

How to create table in Notification Email Scripts

Rameshnathan
Tera Expert

Hi Friends

I have created one "Notification Email Scripts". for Change Report and i have to use this   email script in email notification with table format

1. This is my email script

baseUrl = gs.getProperty("glide.servlet.uri");

var gr = new GlideRecord("change_request");

gr.addEncodedQuery("active=true^assignment_group=dabb461adb373200a91fd001cf96195b");

gr.query();

if (gr.getRowCount() > 0) {

template.print("<br/><br/><br/>Change Request Report:<br/>");

while (gr.next()) {

template.print(" - <a href='" + baseUrl + gr.getLink() + "'>" + gr.getValue('number') + "</a> - " + " - " + gr.short_description + " - " + gr.getDisplayValue('state') + " -   "+ gr.getDisplayValue(' type') + "<br/>");

}

}

2. This above script output is below

Change Request Report:- CHG0030008 - - Short Description - New - null- CHG0030009 - - Short Description - Authorize - null- CHG0030010 - - Short Description - Authorize - null- CHG0030011 - - Short Description - Authorize - null- CHG0030012 - - Short Description - Authorize - null- CHG0030020 - - Short Description - New - null

3. I want to send this output as notification (email) in Table format any one can help me how to create table in email script

6 REPLIES 6

Community Alums
Not applicable

Hi Prateek,

I also facing same issue to email script data in table format in email script. can you help me on this. 
Email Script;

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

getAppDetails("cmdb_ci_business_app", "Business Application(s)");
getAppDetails("cmdb_ci_service_discovered", "Application Service(s)");

function getAppDetails(tableName, title) {
template.print("<br/>");
template.print("<u>" + title + "</u>");
template.print("<br /> <br />");
var gr = new GlideRecord(tableName);
gr.addQuery('assigned_to.name', event.parm2);
gr.addEncodedQuery('install_status!=7');
gr.query();
while (gr.next()) {
if (tableName == "cmdb_ci_business_app") {
template.print("<tr><th> " + gr.number + " </th><th> " + gr.name + " </th><th> " + gr.assigned_to.getDisplayValue() + " </th><th> " + gr.it_application_owner.getDisplayValue() + " </th><th> " + gr.managed_by.getDisplayValue() + "</tr></th>");
} else if (tableName == "cmdb_ci_service_discovered") {
template.print("<tr><th> " + gr.number + " </th><th> " + gr.name + " </th><th> " + gr.assigned_to.getDisplayValue() + " </th><th> " + gr.managed_by.getDisplayValue() + " </th><th> " + gr.u_accountable_remediation_owner.getDisplayValue() + " </th><th> " + gr.u_accountable_remediation_owner.manager.getDisplayValue() + " </th><th> " + gr.u_aro_governance.getDisplayValue() + "</tr></th>");
}
template.print("<br/>");
}

}

email.addAddress("cc", "FAHQ-DL-ConfigurationManagement@firstam.com", "FAHQ-DL-ConfigurationManagement");

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

 

Thanks

Harsh Vardhan
Giga Patron

Hi Ramesh,



you need to create table structure in your mail script.


Please refer the thread below.


Ignore zero when using template.print?