Help please - How to dynamically change recipient of email based on Location field?

Sourabh Saha1
Tera Contributor

I have a requirement on changing email recipient dynamically based on location of the incident. The notification will be same.

For example: if location field of incident has value of QQ2323 then email should be sent to vt.2323@xyz.com or if location value is QQ4545 then email should be sent to vt.4545@xyz.com.

Request to kindly help.

1 ACCEPTED SOLUTION

Allen Andreas
Administrator
Administrator

Hello,

You are unable to use mail script to change the "to" recipient, although you can add to the 'cc' of that notification.

If you don't want this email to go to anyone else, but ONE of those email addresses you mentioned above.

Then you'd want to create an onAfter business rule on the table in question, using appropriate conditions for when you want this notification to be sent.

Within the script of that business rule, you can evaluate:

var re = '';
if (current.field_name == 'value') { //if this field on incident is reference, it's a sys_id value not QQ232
re = 'emailaddress1';
} else if (current.field_name == 'value') { //if this field on incident is reference, it's a sys_id value not QQ232
re = 'emailaddress2';
}
if (re != '') {
gs.eventQueue('event_name', current, re, '');
}

So you'd need to create an event in your instance, then place the event name in the above script where applicable. Then change your notification to send when event you create is trigged and in the "who to send to" tab, choose parm1 contains recipients.

This will allow for dynamic recipient on your notification.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

5 REPLIES 5

Allen Andreas
Administrator
Administrator

Hello,

You are unable to use mail script to change the "to" recipient, although you can add to the 'cc' of that notification.

If you don't want this email to go to anyone else, but ONE of those email addresses you mentioned above.

Then you'd want to create an onAfter business rule on the table in question, using appropriate conditions for when you want this notification to be sent.

Within the script of that business rule, you can evaluate:

var re = '';
if (current.field_name == 'value') { //if this field on incident is reference, it's a sys_id value not QQ232
re = 'emailaddress1';
} else if (current.field_name == 'value') { //if this field on incident is reference, it's a sys_id value not QQ232
re = 'emailaddress2';
}
if (re != '') {
gs.eventQueue('event_name', current, re, '');
}

So you'd need to create an event in your instance, then place the event name in the above script where applicable. Then change your notification to send when event you create is trigged and in the "who to send to" tab, choose parm1 contains recipients.

This will allow for dynamic recipient on your notification.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi Allen,

Thank you very much for your reply.

I am doing this today and will let you know of the outcome. In my real scenario, I have more than 500 locations and their corresponding email ids. Now, instead of writing 500 lines of code, how can we change the email dynamically for the recipient. 

Suppose location is QQ2323 and the corresponding email address is mt.2323@xyz.com and for location QQ4343, the corresponding email address is mt.4343@xyz.com and so on for 500 records.

Thanks

Sourabh

So, actually I am trying to implement Automatic 3-Strike rule. Whenever an incident goes to Awaiting User Info, system should automatically trigger a notification and then when the user replies back the incident moves to In Progress. I have used flow designer earlier to implement auto 3-strike rule but in this case the caller does not have an email id. Instead the email id is trigger based on the location of the incident.

Hi Allen,

I am able to achieve the requirement for 3-Strike rule by creating an event and enabling its firing from Flow Designer.

Thank you very much for your support. I learned something new again.

Thanks

Sourabh