adding User email on CC with email script

Peter Williams
Kilo Sage

Good Morning,

i have a reference field that is pointing to the sys_user table that will display a list of user informatiln. This field is Prepared By. 

What i would like to do in an email script is to have who ever the user is listed in the Prepated By field to be "CC" on the email notification that is sent out.

The sys_user table has their email address listed.

What is the easiest way to do this?

9 REPLIES 9

Harshal Aditya
Mega Sage
Mega Sage

Hi @Peter Williams ,

 

Hope you are doing well

 

Please refer the link below

https://www.servicenow.com/community/now-platform-forum/how-to-set-cc-with-email-content/m-p/1025103

 

Please mark this response as correct or helpful if it assisted you with your question.

Regards,
Harshal

i have this but doesnt work
var gr = new GlideRecord("sc_req_item");
gr.addQuery("sys_id", current.sys_id);
gr.query();
if(gr.next()){
email.addAddress("cc", gr.prepared_by.email.toString(), gr.prepared_by.name.toString());
}

 

sourav1999
Mega Guru

• Use the ‘gs.sendMail()’ method to send emails in ServiceNow

• This method takes a ‘GlideRecord’ object as an argument

• Use the ‘addToCC()’ method to add email addresses to the CC list

• Pass the ‘GlideRecord’ object as an argument to the ‘addToCC()’ method

• Use the ‘setValue()’ method to set the ‘type’ field to ‘cc’

• Pass the email address as an argument to the ‘setValue()’ method

 

For asking ServiceNow-related questions try this :

For a good and optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.

Link - https://nowgpt.ai/

 

For the ServiceNow Certified System Administrator exams try this :

https://www.udemy.com/course/servicenow-csa-admin-certification-exam-2023/?couponCode=NOW-DEVELOPER

i have tried modying my code for this:

var gr = new GlideRecord("sc_req_item");
gr.addQuery("sys_id", current.sys_id);
gr.query();

if (gr.next()) {
var preparedBy = gr.prepared_by;
if (preparedBy) {
var userGR = new GlideRecord("sys_user");
userGR.get(preparedBy);
if (userGR.isValidRecord()) {
var preparedByName = userGR.getDisplayValue("name");
var preparedByEmail = userGR.getValue("email");

email.addAddress("cc", preparedByEmail, preparedByName);
}
}
}

but when i look at the email history still doesnt show the CC