Notification sent from & reply address to be dynamic ... how to?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2017 10:30 AM
Hi,
for sure this is no best-practise, but my customer requires for specific notifications, that the user triggering a specific notification that will be sent to the contact will be set as "from" and the mail address of the assignment group has to be the reply to address.
Any idea how to configure this within a notification?
I'm taking about the "from" and the "reply_to" fields that need to be set dynamically ....
Thank you!
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2017 12:50 PM
This can be done through a mail_script. See the below wiki page for an example:
http://wiki.servicenow.com/index.php?title=Scripting_for_Email_Notifications#Overriding_Email_Fields
Hope this helps!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2017 08:38 AM
Hi Michael,
thank you again! Works fine .. unfortunately only if I use the hardcoded version of entering the adress .. dynamically it does not work.
This is my mail script ...
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
//email.setFrom("mail@test.com"); // works fine
//email.setReplyTo("mail@test.com"); // works fine
email.setFrom(current.sys_updated_by); // does not work
email.setReplyTo(current.assignment_group.email); // does not work
})(current, template, email, email_action, event);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2017 09:13 AM
You will need to ensure you are passing email addresses into these functions. In the "setFrom" function you are passing a username. I would suggest adding a GlideRecord call to the sys_user table to pull the email address associated with that username to pass into the function. The "setReplyTo" function looks good, assuming their is an email set for the group.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2017 06:08 AM
Hi Michel,
still struggeling here.
Somehow ..
email.setReplyTo(current.assignment_group.email); // does NOT work !
BUT
gs.info("Current Group Mail: " + current.assignment_group.email); //shows me the correct email!
In the log I see ....
java.lang.RuntimeException: failed to coerce com.glide.script.fencing.ScopedGlideElement to desired type java.lang.String
Caused by error in <refname> at line 1
==> 1: (function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
2: /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
3: /* Optional GlideRecord */ event) {
4:
Any further idea on that?
Thank you!