Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Adding the author name to the subject line of the email via mail script

lando321
Tera Contributor

Hello all,

I am trying to update the km_approval mail script's subject line to include the author's name.

 

 

 

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {
	
	var obj = new KBKnowledge().getNotificationObject(current);
	var emailContent = {};
	emailContent.templateContent = 
		"Hi  "+obj.approver+",<br/>" + 
	"<br/>" +
	"<a href="+obj.article_link+">"+obj.number+"</a> is awaiting approval.<br/>" +
	"<br/>" +
	"<b>Article Title</b>: "+obj.short_desc+"<br/>" +
	"<br/>" +
	"Please review the article and <a href="+obj.approval_link+">Approve/Reject</a>	it<br/>" +
	"<br/>";	
	email.setSubject(obj.author+"has submitted"+ obj.number+" is awaiting approval.");
	template.print(emailContent.templateContent);
	
})(current, template, email, email_action, event);

 I have tried current.author, event.author, and email,author. Is there a specific way i need to access the object being called? Any insight would be greatly appreciated! 

1 REPLY 1

LorenzVdV
Giga Guru

Your current object is a sysapproval_approver gliderecord (You can see this by checking the table field of your notification). So you need to go to the kba from there.

Add:

var author;

var grKnowledge = new GlideRecord('kb_knowledge');

if(grKnowledge.get(current.document_id))

author = grKnowledge.author.getDisplayValue();

else

author = 'Someone';