How to Add "To" Address in email

Sanjeev Kumar1
Kilo Sage


Hi All,

I am using email methode   ' addAddress(String type, String address, String displayname) - type can be "cc" or "bcc"   '

in my email script with the help of this methode I am able to send "CC" OR "BCC" but

I want to set "TO" address dynamically with the help of e-mail script.

Please let me know it's posible in ServiceNow.

1 ACCEPTED SOLUTION

If this notification is being triggered by an event, it sounds like you will have to use another form of script to set a list of additional users of who you want to add to the "To:" list and pass them into the notification under Event Parm 1 and/or Event Parm 2.



Wiki URL Link:


Email Notifications - ServiceNow Wiki


Event parm 1 contains recipient (Visibile from the Advanced view) Select this check box (true) if the event parameter 1 contains the email recipient. This field is only visible when the Send when field has the value Event is fired.
Event parm 2 contains recipient (Visibile from the Advanced view) Select this check box (true) if the event parameter 2 contains the email recipient. This field is only visible when the Send when field has the value Event is fired.


Example:


gs.eventQueue("change.inserted", current, gs.getUserID(), gs.getUserName());



In the above example, the sys_id returned from "gs.getUserID()" is being passed as Parm1 and the "user_name" is passed as Parm2.



You could use the "eventQueue" function to pass another sys_id or email address.




Let me know if this helps and if this answers your question, please make sure to mark your question answered if so.  



Kind Regards,


Mike


View solution in original post

23 REPLIES 23

If this notification is being triggered by an event, it sounds like you will have to use another form of script to set a list of additional users of who you want to add to the "To:" list and pass them into the notification under Event Parm 1 and/or Event Parm 2.



Wiki URL Link:


Email Notifications - ServiceNow Wiki


Event parm 1 contains recipient (Visibile from the Advanced view) Select this check box (true) if the event parameter 1 contains the email recipient. This field is only visible when the Send when field has the value Event is fired.
Event parm 2 contains recipient (Visibile from the Advanced view) Select this check box (true) if the event parameter 2 contains the email recipient. This field is only visible when the Send when field has the value Event is fired.


Example:


gs.eventQueue("change.inserted", current, gs.getUserID(), gs.getUserName());



In the above example, the sys_id returned from "gs.getUserID()" is being passed as Parm1 and the "user_name" is passed as Parm2.



You could use the "eventQueue" function to pass another sys_id or email address.




Let me know if this helps and if this answers your question, please make sure to mark your question answered if so.  



Kind Regards,


Mike


Thank! Mike It's working



Regards,


Sanjeev Kumar


Please make sure to mark my answer as the correct one if it did answer your question.



Kind regards,


Mike


Hii Mike,


        I know that this is very old discussion but my problem is similar to this. I have set following things



  • Event: exceed_proposed_time
    • Fired by: After new time record redirection
  • Email Notification: Exceed Proposed Time
    • Send to event creator = checked
  • Business Rule: After new time record redirection
    • insert = checked
    • update = checked
    • Script: gs.eventQueue('exceed_proposed_time', current, current.sys_id, "myemail@example.com");


Could you please tell me that where I'm wrong or please let me know if you need more information from myside.


Hi,


I would need to know more details.



The following is based on a couple of assumptions.   1) You've already created the event into the Registry.   2) You've associated the registry event to the notification you want to send when the event is triggered.   3) You either have email sending enabled or you are checking the email log to see if the email was generated



If the assumptions are wrong, I would revisit those and try again as I can see nothing else wrong in the setup.



You can also verify the event logs (System Logs > Events) to see if the event is getting triggered and processed.



The business rule is correct based on what you supplied.   However, you do not need the current.sys_id or the myemail@example.com unless you are specifically using them in the notification.   If not, then its just saving more data for no reason.



Kind Regards,


Mike Pryor