How can I format a field variable in email notifications

allentschumper1
Tera Contributor

Hello -

This is the first time I've ever been asked for this when developing these email notifications, but thought it was an odd request and not sure if it's feasible.

But when you are creating an email notification you can select from a list of fields/variables...

find_real_file.png

as seen above, the additional comments is the exact variable/field I am speaking of.  Now, is there a way to edit how that data comes over onto the email notification?  Meaning, can I adjust the font style and size in how it appears?  

Make sense?

Let the replies roll!

Thank you.

3 REPLIES 3

Tom23
Tera Expert

Hi there,

Short answer - yes! Just highlight the variable and format it as normal (yes, I did make it horrible:)):

find_real_file.png

find_real_file.png

When you do ${comments}...it pulls the data into the email notification like this below...

I tried what you were saying in the template...highlighted ${comments}  but it doesn't give me any way to edit it.  This below is what I want to be able to format.  

 

find_real_file.png

Ah! You can't format comments by the looks of it. You can do it by a quick script though.

Create a new mail script, call it what you like, then use this code (you might want to adjust the span style though as this is my obnoxious black and orange formatting)

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {

          var comments = current.comments.getJournalEntry(-1);
			//split by new line
		var commentsArray = comments.split('\n\n');
	var formattedComments = '';
	for (var i = 0; i<commentsArray.length; i++){
		//because this now means the comments are a string, they don't keep new lines between the summary and the comment. So, break these.
		var splitComment = commentsArray[i].split('\n');
		
		formattedComments+= '<p><span style="font-size: 18pt; color: #ff6600; background-color: #000000;">'+splitComment[0]+'<br>'+splitComment[1]+'</span></p><br>';
	}

	template.print(formattedComments);
})(current, template, email, email_action, event);

 

You can then call the script within the body of the notification as normal - ${mail_script:scriptName}. The end result looks like this:

find_real_file.png

You can obviously adjust the html further to get a nicer decoration//the lines between the comments if you wish.