Broken Email Notification - Yet Preview Works

G24
Kilo Sage

Hello, smart folks.  What am I doing wrong here, please? ...

 

I created a notification which looks like this:

222.png

 

The associated Email script looks like this:

333.png

 

When I use the "Preview Notification" button, and supply the record number of an HR Benefits Case, everything seems to work fine, as you can see here:

000.png

 

But when the email is actually sent out, I don't get any data from the "comments_and_work_notes" field or the mail script, as you can see here:

111.png

 

How can the Preview work, but the actual email functionality Not work?

1 ACCEPTED SOLUTION

G24
Kilo Sage

Found the answer with help from ServiceNow tech support...

There is a ServiceNow bug around the comments_and_work_notes field.  It is documented in an existing knowledge article available here:

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB1587782 

View solution in original post

9 REPLIES 9

Ankur Bawiskar
Tera Patron
Tera Patron

@G24 

are you able to see the comments value in email logs?

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

The field "comments" works fine.  And "work_notes" works fine.  But comments_and_work_notes does Not.

 

But if you are referring to the "sent" log, the comments_and_work_notes field (and script) does not seem to be working there either:

444.png

 

Did I understand you correctly?

Bhupender
Tera Expert

Hi @G24 

Based on the image you provided, it looks like the email script is not fetching the data from the "comments_and_work_notes" field as expected.

 

1-Ensure that the "comments_and_work_notes" field is accessible in the context of the email notification. There might be ACLs (Access Control Lists) that restrict access to this field.

2-Make sure that the "comments_and_work_notes" field actually contains data for the record you are testing with. You can do this by checking the record directly in the ServiceNow instance.

 

3. Double-check the email script for any errors or issues. Ensure that the script is correctly fetching and processing the data from the "comments_and_work_notes" field.

 

here is the debug version of this email script

 

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template, 
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {

template.print("Mail Script START<br/>");
gs.log("Mail Script START");

var $output = current.comments_and_work_notes.getJournalEntry(3);
gs.log("Comments and Work Notes: " + $output);

template.print($output);
template.print("<br/>Mail Script END.");
gs.log("Mail Script END");

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

 

Here we will debug the script and checked is our script work well. 

 

 

I hope this will help you to solve this Issue

 

Please mark it helpful. If this solve your issue.

 

Thanks.  @Bhupender  I added logging to the script as follows.

 

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template, 
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action, 
/* Optional GlideRecord */ event) {

gs.info("GGB Mail Script START");
template.print("Mail Script START<br/>");

var sOutput = current.comments_and_work_notes.getJournalEntry(3);
gs.info("GGB Comments and Work Notes: " + sOutput);
template.print(sOutput);

gs.info("GGB Mail Script END");
template.print("<br/>Mail Script END.");

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

 

When I preview the notification, I see this:

555.png

 

But when the notification runs as a result of a new work note getting added, I see this:

666.png