How to add CC in email script dynamically for a dot walked field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2023 10:06 PM
How to add CC in email script dynamically for a dot walked field.
I have 2 field in which whichever user is present should be added in cc. I tried writing a email script but that doesn't work. below are the 2 fields which are dot walked from sys user table.
highlighted fields are the fields which needs to be added dynamically to cc

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2023 10:26 PM
You can check the example here
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 09:01 PM
This doesn't help @Harish KM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 09:43 PM
HI @Pratiksha Lang1 ,
User below script.
var ccIds = ["suzette.devaughan@example.com", "aman123@test.com", "imran456@test.com"];
for (var emailIndex in ccIds) {
var user = new GlideRecord("sys_user");
user.addQuery("email", ccIds[emailIndex]);//add your query according to your requirment
user.addQuery("email","!=","");
user.query();
if (user.next()) {
email.addAddress("cc", user.getValue('u_hr_people_advisor_ref.email'), user.getDisplayValue());
email.addAddress("cc", user.getValue('u_hr_people_advisor_ref.email2', user.getDisplayValue());
}
}
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 10:08 PM
You can specify copied and blind copied recipients by using the email object within a mail script.
//email.addAddress(type, address, displayname);
email.addAddress("cc","john.copy@example.com","John Roberts");
email.addAddress("bcc","john.secret@example.com","John Roberts");
Can you try like below in mail script :
var hrAdvisorEmail = current.u_hr_people_advisor_ref.email;
var hrAdvisorName = current.u_hr_people_advisor_ref.getDisplayValue();
//Set CC
email.addAddress("cc",hrAdvisorEmail,hrAdvisorName);
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates