- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2022 04:48 PM
Hello,
I have two string fields with a bunch of emails.
My goal is to create a notification that has a dynamic 'to' and 'cc'.
The mechanism is as follows:
1. UI action
2. event
3. email
I am able to fire the notification with correct subject and body, however I cant seem to get the 'to' and 'cc' fields to work..
EMAIL SCRIPT
var parser = JSON.parse(event.parm1); // parse the json
//gs.error('TO_CC_Body_email_script fired : ' + parser.to2 ); // notification passes the correct parameters
// email.setReplyTo(parser.to2); // not working
// email.addAddress("to", 'email2@gmail.com'); // not working
//email.setReplyTo("abc@yourcompany.com"); // not working
email.setSubject("HARDCODED SUBJECT from email script!! ");
template.print("PRINT STATEMENT " );
NOTIFICATION::
here is the email log::
As you can see, I am very close. I was able to get the event to fire, but the 'to' and the 'cc' fields are not right.
help!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2022 04:58 PM
Hi Juan,
I am not sure if You can set TO using email script. You can do that using event queue
How to Add "To" Address in email
How to set to address in email scripts?
whereas CC can be set using .email.addAddress('cc','email','name')
and to check cc it will not show like that
yout have to go to Configure > form layout and bring "Copied" field to form
There you can see everyone you added in CC
Mark Correct or Helpful if it helps.
***Mark Correct or Helpful if it helps.***

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2022 04:58 PM
Hi Juan,
I am not sure if You can set TO using email script. You can do that using event queue
How to Add "To" Address in email
How to set to address in email scripts?
whereas CC can be set using .email.addAddress('cc','email','name')
and to check cc it will not show like that
yout have to go to Configure > form layout and bring "Copied" field to form
There you can see everyone you added in CC
Mark Correct or Helpful if it helps.
***Mark Correct or Helpful if it helps.***
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2022 05:13 PM
Hi, this question is basically the same as the one you asked here
and multiple questions for the same issue are unnecessary and less likely to result in a clear outcome\answer to your question.
As Yousaf has mentioned you can use mail_script to set CC but not TO, probably as TO must exists for an email notification to be triggered.
Otherwise your formatting seems to match the structure defined in the documentation
Example scripting for email notifications (servicenow.com)
Without details of your testing process I would guess that you are trying to set 'to' in your mail-script and this causes the script to fail and subsequent methods do not run?
As a solution I would update the sysevent, and send 'to' as a separate parameter (either parm1 or parm2) you can then set 'TO' in the who will receive section of your Notification using the field 'Event param X contains recipient'. Then you can user the object you are creating as your other event parm, to set other values in your mail_script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2022 01:48 PM
FOR CC YOU can use
email.addAddress("cc","email_address_of_the_user","Name_of_ther_user");
For to address i think you are sending it in parm1 of the event by encoding the user in JSON
instead of that send the user sys_id directly in the parm 1 like below
gs.eventQueue("your_event_name",your object , "user_sys_id","");
then in the notifications of to who will receive and select the check box "event parm 2 contains recepient"