How to add CC in email script dynamically for a dot walked field

Pratiksha Lang1
Kilo Sage

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.

PratikshaLang1_0-1696309474570.png

 

highlighted fields are the fields which needs to be added dynamically to cc

 

PratikshaLang1_1-1696309535885.png

 

 

 

4 REPLIES 4

Harish KM
Kilo Patron
Kilo Patron

This doesn't help @Harish KM 

Anand Kumar P
Giga Patron
Giga Patron

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

Vishal Birajdar
Giga Sage

Hi @Pratiksha Lang1 

 

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);


 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates