- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2023 07:46 AM
Hello - I am working with a custom table extended from the Task table. I have approvals configured in a workflow for this table. When an approval record is rejected, I am trying to add several recipients from 2 User Reference fields on the custom table. The notification is being sent OK, however my mail script doesn't appear to be working, to add recipients from the custom table to the rejection mail notification. Was hoping someone could take a look at my script and see if I am going about it the wrong way.
Here is my mail script:
(function runMailScript(current, template, email, email_action, event) {
var ecn = current.getValue('document_id');
var ecnfields = new GlideRecord("custom_table_here");
ecnfields.addQuery("sys_id", ecn);
ecnfields.query();
if (ecnfields.next()) {
var behalf = ecnfields.getValue('on_behalf_of');
var initiate = ecnfields.getValue('initiated_by');
email.addAddress("cc", behalf.email.toString(), behalf.name.toString());
email.addAddress("cc", initiate.email.toString(), initiate.name.toString());
}
})(current, template, email, email_action, event);
Thank you!!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2023 08:04 AM - edited 10-30-2023 08:07 AM
Hi @jlaue
Which should be correct is these 2 lines.
var behalf = ecnfields.getValue('on_behalf_of');
var initiate = ecnfields.getValue('initiated_by');
I assume these fields on_behalf_of and initiated_by are the reference fields.
So let's try the below adjustment.
(function runMailScript(current, template, email, email_action, event) {
var ecn = current.getValue('document_id');
var ecnfields = new GlideRecord("custom_table_here");
ecnfields.addQuery("sys_id", ecn);
ecnfields.query();
if (ecnfields.next()) {
email.addAddress("cc", ecnfields.on_behalf_of.email.toString(), ecnfields.on_behalf_of.name.toString());
email.addAddress("cc", ecnfields.initiated_by.email.toString(), ecnfields.initiated_by.name.toString());
}
})(current, template, email, email_action, event);
Let me know if it works for you.
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2023 08:04 AM - edited 10-30-2023 08:07 AM
Hi @jlaue
Which should be correct is these 2 lines.
var behalf = ecnfields.getValue('on_behalf_of');
var initiate = ecnfields.getValue('initiated_by');
I assume these fields on_behalf_of and initiated_by are the reference fields.
So let's try the below adjustment.
(function runMailScript(current, template, email, email_action, event) {
var ecn = current.getValue('document_id');
var ecnfields = new GlideRecord("custom_table_here");
ecnfields.addQuery("sys_id", ecn);
ecnfields.query();
if (ecnfields.next()) {
email.addAddress("cc", ecnfields.on_behalf_of.email.toString(), ecnfields.on_behalf_of.name.toString());
email.addAddress("cc", ecnfields.initiated_by.email.toString(), ecnfields.initiated_by.name.toString());
}
})(current, template, email, email_action, event);
Let me know if it works for you.
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2023 08:15 AM
That worked, thank you so much for your help!!