how to add email recipients via email script and according to conditions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2024 08:28 PM
Hi,
I would like to create a schedule email for change task ticket. However, the email template is all using the same one but it is based off of different locations and these locations have different email recipients.
Is there a way for me to do this via email script similar to adding cc email?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2024 08:54 PM
Hi @susunow ,
yes you can, just i want to know is location information present on change task or change record
if it is present in change task and if your email notification on change task then you can script as below
Create system property like below locations_email_map
{ "abcd1234abcd1234abcd1234abcd1234": "ny-team@company.com", "wxyz5678wxyz5678wxyz5678wxyz5678": "sf-team@company.com", "mnop5678mnop5678mnop5678mnop5678": "london-team@company.com" }
in email script write this
var locationSysId = current.u_location; // if it is reference field
// Get the location-email map from the system property
var locationEmailMap = gs.getProperty('locations_email_map');
var locationEmailObject = JSON.parse(locationEmailMap);
email.setTo("default.email@company.com");
var recipientFound = false;
for (var sysId in locationEmailObject) {
if (locationSysId == sysId) {
email.addAddress("cc", locationEmailObject[sysId]);
recipientFound = true;
break;
}
}
Thanks,
BK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2024 08:57 PM
Hi thank you for this. However, im not looking for the cc but recipient (to) emails. Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2024 02:26 AM
Hi thank you for this. However, im not looking for the cc but recipient (to) emails. Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2024 05:03 AM - edited 10-04-2024 05:03 AM
Hi @susunow
you cannot set the recipients via email script. Only CC and BCC is allowed.
if you want to do , in business rule trigger event send the email address and enable recipient in event parm1 then it will work fine
example BR script:
var locationSysId = current.u_location ? current.u_location.toString() : '';
var locationEmailMap = gs.getProperty('locations_email_map');
var locationEmailObject = JSON.parse(locationEmailMap); // Parse the JSON string to an object
for (var sysId in locationEmailObject) {
if (locationSysId === sysId) {
gs.eventQueue('event.name', current, locationEmailObject[sysId]);
}
}
