Hide name of support agent in email for Additional Comment

VShine
Mega Guru

Hello Experts,

I have requirement to hide name of HR agent hidden in email notification for "Case Commented".

If Additional Comment is added by "HR Agent" it should appear as "HR Agent" instead of User name.

If added by customer /opened_for, then display the name.

This needs to be in "Email". I tried using mail script but no success. Here is the mail script I got from another community post.

find_real_file.pngemail is generated with following output

find_real_file.png

 

1 ACCEPTED SOLUTION

Oh that's an easy enough fix.  Variable references are CAPS sensitive in javascript, another good reason to copy+paste your variables instead of typing them.  Just match case and you should get rid of that error, because "ticketId" is completely different from "ticketID"

View solution in original post

16 REPLIES 16

gs.print is not a function in email scripts.  You typically only use gs.print in background scripts.  To print information in the email via the email script, use template.print:

https://docs.servicenow.com/bundle/paris-servicenow-platform/page/script/server-scripting/reference/...

@Justin thank you for response.

I update script with template.print....still no success.

(function runMailScript (current, template, email, email_action, event) {
var ticketId = current.getUniqueValue();
	var journalEntry = new GlideRecord('sys_journal_field');
	journalEntry.addQuery('element_id',ticketID);

journalEntry.addQuery('element', 'comments'); //Provide name of the journal field, here the field name is 'comments'


journalEntry.query();
while(journalEntry.next()) {
template.print('Comment : ' + journalEntry.value);

template.print('Commented On : ' +journalEntry.sys_created_on + '<hr>');
	

}

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

Can you elaborate on "no success"?  Is the email not sending, is the email sending but the email script isn't printing anything?  Printing something but not everything?  Giving your input (the script) is important, but for each input we also need to know the output (the email) to effectively debug.

@Justin Email is triggered. I am previewing email, 

Here is notification (Payroll case commented)

find_real_file.png

When I am commenting Payroll case, email is triggered as is (with commented by user name)

find_real_file.png

So it looks like the email script isn't printing anything.  Try adding the following line of code above your ticketId declaration: 

template.print('-----------TESTING-----------');

And if that doesn't print when you resend the email, I would check to make sure the name of your email script is exactly the same as the one you have called in your notification.

If that DOES print, that means there is something wrong with your query and therefore it will never enter into the "while" loop.  My guess is there is a typo or "current.getUniqueValue()" isn't returning the what you'd expect.  If this is the case, it's probably worth logging:

template.print(journalEntry.getEncodedQuery());

either right before or right after your query() call.