- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2022 05:24 PM
I've been reading through a few threads related to this but am not sure how to get started to perform this.
For context, we have an email notification that is kicked off when a record is inserted into a custom table in one of our scoped applications. This custom table's record insertions include a user and their manager as fields.
When the notification is sent, the user's manager is included as a recipient. However, the criteria has changed and the Manager needs to be CC'd now. I know this capability is available in Flow Designer, but unfortunately the From field is not, which is also a requirement for this email notification.
I am aware I need to build out a Notification Email Script to CC the manager, but I am unsure of how to properly grab the manager information.
My knowledge of GlideRecord is limited, but am I able to use current.manager.email to grab the Manager's email directly since it is part of the accessible fields in the "Users/Groups in fields" (recipient_fields) portion? Or do I need to do something else to grab the manager's name and email to properly CC them?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2022 06:29 PM
Hi
yes, as you already figured out there is no individual field for CC addresses on the notification form.
The only way to add CC addresses is via scripting. Create a email script as follows
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
email.addAddress("cc", current.manager.email, current.manager.getDisplayValue());
})(current, template, email, email_action, event);
And then call that script in your notification. See https://docs.servicenow.com/bundle/rome-servicenow-platform/page/script/server-scripting/concept/c_S... to learn how this has to be done
Kind regards
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2022 06:29 PM
Hi
yes, as you already figured out there is no individual field for CC addresses on the notification form.
The only way to add CC addresses is via scripting. Create a email script as follows
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
email.addAddress("cc", current.manager.email, current.manager.getDisplayValue());
})(current, template, email, email_action, event);
And then call that script in your notification. See https://docs.servicenow.com/bundle/rome-servicenow-platform/page/script/server-scripting/concept/c_S... to learn how this has to be done
Kind regards
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2022 11:02 AM
This was helpful, but I did run into one problem.
The CC did not work until I altered current.manager.email to the below:
email.addAddress("cc", current.manager.email.getDisplayValue(), current.manager.getDisplayValue());
After performing the above, however, now the email is duplicated to the original recipient. That is, one email is generated to just the recipient, then an email is generated to the recipient and their manager.
When I statically set the CC address such as email.addAddress("cc", "test@test.com", "Test Person"), it kicks off only one email, to the recipient and then this static email.
Does anyone know why that is the case and how to resolve it? Although the dynamic CC'ing appears to work now, I do not want the original recipient to receive two duplicate emails. The below is a poor screenshot, but as you can tell from the created time, two emails are kicked off at the same time, only one is to the original recipient, and the other is to the recipient and their manager.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2022 11:15 AM
I was mistaken, I neglected to see that we have an older notification in our Dev instance that is duplicating these. Disregard my above comment,
I really appreciate the input.