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

Tony Chatfield1
Kilo Patron

Hi, if you can share your notification email script code,
the forum will be able to review and assist\advise where and why your script is not working as expected.

@Tony Chatfield Here is the script I am trying to use. It is working as expected when running as Background script(screenshot #2).....

I tried both of these script...... First one shall post " HR Agent" when comment added by assigned to, and leave alone when added by customer. While Second one should remove "Commented by" name. None of them is working for me.

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

var ticketId = current.getUniqueValue();
var ticketCreBy = current.opened_by;
var ticketUptBy = current.assigned_to;
var journalEntry = new GlideRecord('sys_journal_field');

journalEntry.addQuery('element','comments');
journalEntry.addQuery('element_id',ticketID);
journalEntry.orderByDesc('sys_created_on');
journalEntry.query();

while (journalEntry.next()) {
    vCommentBy ="";
    var vJcreatedBy = journalEntry.sys_created_by;

    if (vJcreatedBy == (ticketUptBy ||ticketCreBy)) {
        var vUsrName = new GlideRecord('sys_user');
        vUsrName.addQuery('user_name',vJcreatedBy );
        vUsrName.query();

        while (vUsrName.next()) {
            vCommentBy == "";
            vCommentBy = vUsrName.name;
        }
    }
    else {
        vCommentBy == "";
        vCommentBy = "HR Agent";
         }        
    template.print('<div><span style="font-size: 12pt;">');
    template.print('<b>' + journalEntry.sys_created_on + '</b>' + 'from' + vCommentBy + '<br />');
    template.print('journalEntry.value + '<hr>');
}
}) (current, template, email, email_action, event);
(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.addQuery('element_id', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'); //Provide sys_id of the record on which the journal field is present, i.e, sys_id of the change request

journalEntry.query();
while(journalEntry.next()) {
gs.print('Comment : ' + journalEntry.value);
//gs.print('Commented By : ' + journalEntry.sys_created_by);
gs.print('Commented On : ' +journalEntry.sys_created_on + '<hr>');
	

}

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