- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2021 12:05 PM
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.
email is generated with following output
Solved! Go to Solution.
- Labels:
-
Instance Configuration
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2021 01:04 PM
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"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2021 09:57 AM
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:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2021 10:43 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2021 10:59 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2021 11:20 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2021 11:32 AM
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.