Notification Email Scripts

Aswin Chandras1
Tera Contributor

Hi All,

 

I have written a e-mail script to display the incident summary in the notification.

 

Email script:

var incident_record = current.sysapproval.getRefRecord();
if(incident_record){
    template.print("<table>");
    template.print("<tr><td><strong>Caller:</strong></td><td>" + incident_record.caller_id.getDisplayValue() + "</td></tr>");
    template.print("<tr><td><strong>Assignment group:</strong></td><td>" + incident_record.assignment_group.getDisplayValue() + "</td></tr>");
    template.print("<tr><td><strong>Assigned to:</strong></td><td>" + incident_record.assigned_to.getDisplayValue() + "</td></tr>");
    template.print("</table>");
    template.print("<div><strong>Description:</strong></div><div>" + incident_record.description + "</div>");
    template.print("<div>&nbsp;</div>");
 
 
Notification:
${mail_script:cf_incident_mim_approval_summary}
 
But it is not coming as expected.
 
9 REPLIES 9

t_sadahisa
Giga Guru

Hello @Aswin Chandras1 

 

I assume you are likely intending to send notifications from the sysapproval_approver records.

 

Since the sysapproval column in sysapproval_approver is a reference field for the task table, it cannot access fields defined in incident.

 

I think it would be best to retrieve the sys_id from the sysapproval column and use glideRecord to fetch the data.

Hi @t_sadahisa 

 

Can you help me on getting the script if you could.

 

Thanks

Hi @Aswin Chandras1 

 

Here is the sample code.
I haven't thoroughly tested it, so please check it carefully.

 

var incident_sysid = current.sysapproval.getValue();

var incident_record = new GlideRecord('incident');
incident_record.get(incident_sysid);

if(incident_record){
    template.print("<table>");
    template.print("<tr><td><strong>Caller:</strong></td><td>" + incident_record.caller_id.getDisplayValue() + "</td></tr>");
    template.print("<tr><td><strong>Assignment group:</strong></td><td>" + incident_record.assignment_group.getDisplayValue() + "</td></tr>");
    template.print("<tr><td><strong>Assigned to:</strong></td><td>" + incident_record.assigned_to.getDisplayValue() + "</td></tr>");
    template.print("</table>");
    template.print("<div><strong>Description:</strong></div><div>" + incident_record.description + "</div>");
    template.print("<div>&nbsp;</div>");

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Aswin Chandras1 

I believe you are writing notification on sysapproval_approver table

share some screenshots and extra details

If yes then modify the script as this

var incident_record = new GlideRecord('incident');
incident_record.addQuery('sys_id', current.sysapproval);
incident_record.query();
if (incident_record.next()) {
        template.print("<table>");
        template.print("<tr><td><strong>Caller:</strong></td><td>" + incident_record.caller_id.getDisplayValue() + "</td></tr>");
        template.print("<tr><td><strong>Assignment group:</strong></td><td>" + incident_record.assignment_group.getDisplayValue() + "</td></tr>");
        template.print("<tr><td><strong>Assigned to:</strong></td><td>" + incident_record.assigned_to.getDisplayValue() + "</td></tr>");
        template.print("</table>");
        template.print("<div><strong>Description:</strong></div><div>" + incident_record.description + "</div>");
        template.print("<div>&nbsp;</div>");
    }

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader