Email client templates when replying from the Record Activity

Marcel H_
Tera Guru

I've been working on a request from an internal team to send email from records within ServiceNow. Recently I added the glide.ui16.emailStreamResponseActions to show the buttons in the email stream, and the published workaround/fix to make sure that mail sent from those buttons updates the activity stream.

What I'm not sure about is where you can set an email client template like you can with the normal email client button. The same window pops up with using the mail stream buttons, but is pre-populated with different From and Reply to addresses than I want, and end users aren't going to want to delete what is there and change it (besides being prone to errors that way).

If there is a way to change the templates used, that would be great.

1 ACCEPTED SOLUTION

emaasalmi
Kilo Sage

In my actual script I'm calling another function to get the instance email address from a system property I have created for it, but basically you could just do:

getFromEmailForReplyButtons: function(){
	var fromEmail = '';
	if (current.target_table == 'u_customtable'){
		fromEmail = 'Mailbox display name <email.address@example.com>'
	}
	return fromEmail;
}

Or if you want to create a system property for your email address (preferred way!), you would get it from the property this way.

getFromEmailForReplyButtons: function(){
	var fromEmail = '';
	if (current.target_table == 'u_customtable'){
		fromEmail = gs.getProperty('your.property.for.instance.email');
	}
	return fromEmail;
}

View solution in original post

6 REPLIES 6

Marcel H_
Tera Guru

Still currently looking for possible solutions to this. Since the buttons seem to call the same email client, but fill in fields like "From" and "Reply to" automatically, it seems like there should be a way to control where or how that gets pulled in.

emaasalmi
Kilo Sage

I had a very similar requirement and I think I found the solution. Here are my findings in case you still need help with this.

The Email Client Templates for sys_email -table are the ones you need to modify ("forward-received", "forward-sent", "replyall-received", "replyall-sent", "reply-received" and "reply-sent").

When you click the "Reply" button on an email that was received by your insance, system uses the "reply-received" template. When the "Reply" button is clicked on an email that was sent from your instance, system uses the "reply-sent" template. If the "Forward" button is clicked on an email that was received by your instance, modify the "forward-received"-button etc.

In my case I wanted to modify the From/Reply to address only when the buttons were used on a custom table, so on the Email Client Template's From/Reply to fields I call a Script include (javascript:new myScriptInclude().myFunction();).

In the function I then check if current.target_table == 'u_mytable' (current object here refers to the sys_email record you are using the replying/reply all/forward buttons on), and then if it matches I return the from/reply to address I want to have on the template. If the sent/received email's target table is not my custom table, I return an empty string. When empty string is returned the system seems to use the instance's default email account address which was exactly what I wanted to do anyway.

 

This sounds very promising. Do you mind sharing the code in your script include as an example for what you're doing currently? 

I have a feeling that for our instance this will start out with one custom table doing this, but other tables will likely be added to the checks in the function. I'm sure one the base functionality is set up and working, adding other custom tables shouldn't be much of an issue.

 

Thanks in advance if you're able to share your code! šŸ™‚

emaasalmi
Kilo Sage

In my actual script I'm calling another function to get the instance email address from a system property I have created for it, but basically you could just do:

getFromEmailForReplyButtons: function(){
	var fromEmail = '';
	if (current.target_table == 'u_customtable'){
		fromEmail = 'Mailbox display name <email.address@example.com>'
	}
	return fromEmail;
}

Or if you want to create a system property for your email address (preferred way!), you would get it from the property this way.

getFromEmailForReplyButtons: function(){
	var fromEmail = '';
	if (current.target_table == 'u_customtable'){
		fromEmail = gs.getProperty('your.property.for.instance.email');
	}
	return fromEmail;
}