Case Notification when case updated by customer

MStritt
Tera Guru

I'm creating a notification on the Case table, that will send a notification when a case has been updated by the customer. In the 'What it will contain' portion of the notification, I'd like to include the most recent update made by the customer. Currently, I've added the 'Additional comments' variable, but it displays all additional comments in the case. I only want to show the most recent additional comment by the customer, that triggered the notification.

2 ACCEPTED SOLUTIONS

Nakka Bhavani S
Tera Expert

Hello MStritt,

 

You need to use email script to achieve this requirement.

 

Please follow the below steps.

1. Create a Email notification script and add the below script.

Lets assume the name of this script is : case_email_notification

 

var latestCom = new GlideRecord('sys_journal_field');   // Sys Journal is the table which contains all work notes and comments
latestCom.addEncodedQuery('element_id=' + current.sys_id);  //no need to change this
latestCom.orderByDesc('sys_created_on');
latestCom.setLimit(1);  // this will ensure to pick the latest comment made on the case
latestCom.query();
if (latestCom.next()) {
template.print('<p><font size="6" color="#808080" face="helvetica">');
template.print(latestCom.value);   // printing the latest comment. no need to check this field until unless you modified the value field in Sys Journal table(Which I doubt)
template.print('</font></p>');

 

2. Open your notification and add this Email notification script in the message HTML like below:


 

${mail_script:case_email_notification} .

 

It will fix your issue. Check and let me know if it fixed your issue or not.

 

Thanks,

Bhavani.

 

 

View solution in original post

@MStritt I'm surprised you didn't accept my solution, Basically you don't need to gliderecord journal table, you can simply do like below. Can you accept my solution as well ?

Email script

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

	template.print('Comments '+current.comments.getJournalEntry(1));

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

And in notification 'What will contain' just call script

${mail_script:test123}

Please hit like and mark my response as correct if that helps
Regards,
Musab

View solution in original post

8 REPLIES 8

Musab Rasheed
Tera Sage
Tera Sage

Hello,

Create email script then call in Notification, this is very simple, here is the example

https://www.servicenow.com/community/developer-forum/want-to-show-only-the-last-additional-comment-o...

Please hit like and mark my response as correct if that helps
Regards,
Musab

@MStritt I'm surprised you didn't accept my solution, Basically you don't need to gliderecord journal table, you can simply do like below. Can you accept my solution as well ?

Email script

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

	template.print('Comments '+current.comments.getJournalEntry(1));

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

And in notification 'What will contain' just call script

${mail_script:test123}

Please hit like and mark my response as correct if that helps
Regards,
Musab

Nakka Bhavani S
Tera Expert

Hello MStritt,

 

You need to use email script to achieve this requirement.

 

Please follow the below steps.

1. Create a Email notification script and add the below script.

Lets assume the name of this script is : case_email_notification

 

var latestCom = new GlideRecord('sys_journal_field');   // Sys Journal is the table which contains all work notes and comments
latestCom.addEncodedQuery('element_id=' + current.sys_id);  //no need to change this
latestCom.orderByDesc('sys_created_on');
latestCom.setLimit(1);  // this will ensure to pick the latest comment made on the case
latestCom.query();
if (latestCom.next()) {
template.print('<p><font size="6" color="#808080" face="helvetica">');
template.print(latestCom.value);   // printing the latest comment. no need to check this field until unless you modified the value field in Sys Journal table(Which I doubt)
template.print('</font></p>');

 

2. Open your notification and add this Email notification script in the message HTML like below:


 

${mail_script:case_email_notification} .

 

It will fix your issue. Check and let me know if it fixed your issue or not.

 

Thanks,

Bhavani.

 

 

Can I ask an additional question? I've noticed that I'm getting an email notification every time the case is updated. I only want one notification when the customer updates the case for the most recent update. I have 'Updated' selected in the 'When to send' part of the notification. I believe that's why. Should I uncheck 'Updated' and check 'Inserted'?