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

@Justin you are right.

first print statement "Testing" does get print but not the element_id.

find_real_file.png

Here is the previewed email.

find_real_file.png

I'd recommend adding some other template.print()'s to debug: If it isn't getting to the getEncodedQuery() line, I'd check and see if the ticketID is what you expect.  If it is, maybe the GlideRecord isn't able to query due to some scoping restrictions, in which case adding a try/catch statement around the query and gs.info()'ing the catch error might give you some insight.

@Justin I add info message in script. and its saying error in line 6

find_real_file.png

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"

@Justin it fix the issue....Thank you so much.

Here is the final script in case anyone needed in future.

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,/* Optional EmailOutbound */    email, /* Optional GlideRecord */ email_action,/* Optional GlideRecord */event) {
	
	var ticketId =current.sys_id;
	var journal = new GlideRecord('sys_journal_field');
	
	journal.addQuery('element_id',ticketId);
	
	

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

//journalEntry.addQuery('element_id', 'ticketId'); //Provide sys_id of the record on which the journal field is present, i.e, sys_id of the change request

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

}

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