Email Notification Script

Ken83
Mega Guru

Hello Community,

        I'm doing some re-factoring on my email notifications and I've come across a scenario where I have 2 notifications on the same table(sc_task) for the same reason but with different recipients because the information is slightly different(1 or 2 lines difference). These 2 emails can use the same email script but there is   1 roadblock here. Is there a way for me to determine, in the email notification script, who the recipient of the notification is?

Ive tried using the email_action object but many of the properties inside are empty. Here is a small snippet of the properties i looked at...

find_real_file.png

1 ACCEPTED SOLUTION

Jim, great content and useful as expected. The method that you outlined in that post is a little more complicated than I need for my situation however, you brushed right over EXACTLY what I was looking for. Here...


find_real_file.png


The email_action object provides access to 3 properties to obtain the recipients of the email notification..



find_real_file.pngis accessed via email_action.getValue('recipient_fields') and correlates to this field on the email notification record


find_real_file.png



find_real_file.pngis accessed via email_action.getValue('recipient_groups') and correlates to this field on the email notification record


find_real_file.png



find_real_file.pngis accessed via email_action.getValue('recipient_users') and correlates to this field on the email notification record


find_real_file.png



That drawn out explanation was mainly for anyone else who finds this article but, I was not aware of I could access the properties of the email_action object that way because when logging it, those values are empty but when I use .getValue(), they actually return values. Anywho, that gives me what I need to continue my consolidation efforts. Thanks everyone for the assist here!


View solution in original post

11 REPLIES 11

Malaya
Giga Expert

in the specific loop you can override email address by using below function.



find_real_file.png


I don't need to modify those email properties, I simply need to see who the recipient of the email will be from within the mail_script.


I think you need to explain the complete scenario here... I might have mis-understood your requirement. can you explain it via example end to end scenario?



Thanks,


Malaya


Sure thing. So, lets say I have record A(an incident) that gets commented by the end user. That will generate an email notification to the person assigned to record A to let them know what happened.



The content of that email notification is generated using a mail script. This mail script is also being used for a similar scenario when the person assigned to record A comments the record. Which will generate an email notification to the caller with the issue.



So, with those 2 scenarios, I have 2 email notification records, 1 for each scenario. Currently, there are 2 different mail scripts as well for each notification. Based on that scenario above, the only difference is going to be 1 or 2 lines of that email content that will be removed depending on who its going to and of course the recipient is different.



I have set the recipients of the emails on the email notification record like so...


find_real_file.png



What I am trying to accomplish, is to retrieve the values set here, from the mail script. This will allow me to use 1 email script to handle multiple notifications if I am able to tell who the recipient is. Hopefully that's a bit clearer.


Jim Coyne
Kilo Patron

You can't really tell who the recipients are (at least not easily), BUT, there is something you can do so Email Scripts output different data based on the Notification being sent, which would typically have different users defined there.



Take a look at this post - Outputting Different Information From One Email Script