Email script - template print based on recipient_field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2018 08:07 AM
Hi SN Community,
Running into a requirement that I have yet to have before. After doing some research it looks like its possible but I need to clear things up as I am unsure if its truly functioning as intended.
Requirement - Use one email notification that has an email script in it which inserts a mailto link IF the recipient is 2 of the four in the Users/Groups in field.
Users/Groups in field -
Assigned to
Assignment Group manager
Assignment Group Subdomain lead
Assignment Group Domain lead
Only the Assignment Group Subdomain lead & Assignment Group Domain lead should see the link. There is a chance that the Assignment Group manager & the Assignment Group Subdomain lead are the same which is why we want it in one notification so it won't send them two notifications if we separate the notifications.
When I use the below mentioned script it seems that in the email logs everyone is getting the same email as all 4 recipients names are in the same email log. I am getting one email in our test inbox and it contains my first if statement and i never get one with the "output2".
Thoughts? I assume it is because it is just saying, yes the subdomain leader exists in the recipient fields so just put the link in the email that gets sent... but how do i make it so it checks each recipient?
(function runMailScript(current, template, email, email_action, event) {
var fields = email_action.getValue('recipient_fields');
if (fields == current.assignment_group.u_subdomain_leader || current.assignment_group.u_reporting_domain_leader) {
template.print('test- ${mailto:mailto.incident}.');
} else if (fields == current.assignment_group.manager || current.assigned_to) {
template.print('Output2');
}
})(current, template, email, email_action, event);
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2018 09:55 AM
I could be wrong here, but I'm pretty sure the issue is with your logical OR statement. I think the way you are writing it is having it check if fields is equal to assignment group subdomain leader or if assignment group reporting domain leader is not falsy. Assuming there is always an assignment group reporting domain leader then your if check will always match that. I think what you actually want is:-
(function runMailScript(current, template, email, email_action, event) {
var fields = email_action.getValue('recipient_fields');
if (fields == current.assignment_group.u_subdomain_leader || fields == current.assignment_group.u_reporting_domain_leader) {
template.print('test- ${mailto:mailto.incident}.');
} else if (fields == current.assignment_group.manager || fields == current.assigned_to) {
template.print('Output2');
}
})(current, template, email, email_action, event);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2018 10:15 AM
Thank you for the reply Colin. I believe the logic in and of itself is just wrong lol. Right now I have an entire notification built out that has a script mentioned in it to insert an extra line based off of the recipient. From what it seems is that it doesn't run the email script on the notification level for each recipient. It will just say ok im sending Email1 to A,B,C,D. Sending email1 > run script > domain leader exists > insert link from script > Send to A,B,C,D.
I need it to run the script for each recipient but its like im sending one email with people CC'ed instead of sending 4 separate emails with a dynamic email body based off their role in the assignment group.