Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

CC does not populate two values

samadam
Kilo Sage

I have an email script to send to the creator and an email address. I have the following in the mail script:

 

email.addAddress("cc", 'test@test.com', 'Change Management');              
var created_by = current.getValue("current.opened_by");
    if (created_by) {
        var grUser = new GlideRecord("sys_user");
        if (grUser.get("user_name", created_by)) {
            email.addAddress("cc", grUser.getValue("email"), grUser.getDisplayValue());
        }
    }

Only test@test.com shows up in the CC field on the list view. How can I get both?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@samadam 

you need not query sys_user.

use this

email.addAddress("cc", 'test@test.com', 'Change Management');
if (current.opened_by) {
    email.addAddress("cc", current.opened_by.email.toString(), current.opened_by.getDisplayValue());
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

4 REPLIES 4

Anand Kumar P
Giga Patron

Hi @samadam ,

Try below script ,check if user has valid email.

        var userEmail = grUser.getValue("email");

        if (userEmail) {

            email.addAddress("cc", userEmail, grUser.getDisplayValue());

}

If my response helped, please mark it as the accepted solution and give a thumbs up👍.
Thanks,
Anand

 

 

Omkar Mone
Mega Sage

Can you check if this works for you? 

 

email.addAddress("cc", 'test@test.com', 'Change Management');

var created_by = current.getValue("opened_by");
if (created_by) {
var grUser = new GlideRecord("sys_user");
if (grUser.get("sys_id", created_by)) {
var userEmail = grUser.getValue("email");
if (userEmail) {
email.addAddress("cc", userEmail, grUser.getDisplayValue());
}
}
}

Ankur Bawiskar
Tera Patron
Tera Patron

@samadam 

you need not query sys_user.

use this

email.addAddress("cc", 'test@test.com', 'Change Management');
if (current.opened_by) {
    email.addAddress("cc", current.opened_by.email.toString(), current.opened_by.getDisplayValue());
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

samadam
Kilo Sage

That worked. Thank you