CC email address not working

MPP22
Mega Guru
Hello, we have 3 below custom tables in scoped application. 1. ABC 2. DFG > This table has a reference field from table ABC 3. XYZ > This table has a reference field from table DFG Now below script built on the "XYZ" table to send an email to approvers (trying to get this data from ABC table via dot walk) in CC. But somehow could not see these approvers in CC under email logs. The below script working well in background-script and gives me approver email, name. Appreciate urgent help here to understand where could be the issue /how can we troubleshoot/fix this. var grOp = new GlideRecord('XYZ'); grOp.addQuery('sys_id', current.getUniqueValue()); grOp.query(); while (grOp.next()) { var kri = grOp.transaction; var grKri = new GlideRecord('DFG'); grKri.addQuery("sys_id", kri); grKri.query(); while (grKri.next()) { var app = grKri.ABC.approver.toString().split(","); var cnt = app.length; for (var i = 0; i < cnt; i++) { var user = new GlideRecord("sys_user"); user.addQuery("sys_id", cnt[i]); //user.addQuery("notification", 2); //email //user.addQuery("email", "!=", ""); user.query(); while (user.next()) { email.addAddress("cc", user.email, user.getDisplayValue()); } } } }
1 ACCEPTED SOLUTION

MPP22
Mega Guru

Those who replied and helped were really appreciated. Thanks all for that !! @Murthy Ch @Sharanya Hegde3 @Mohit Kaushik 

 

This issue has been fixed now by referring OOB emai script "pwd.enrollment_reminder". We dont need to check array length and no need to pass array data with counter in addquery which was causing this issue (Still not sure of logic behind this). Refer to the updated piece of code for reference.

Happy Learning from mistakes !!!

 

var app = grKri.ABC.approver.split(",");
var appuser = new GlideRecord("sys_user");
appuser.addQuery("sys_id",app);
//appuser.addQuery("notification", 2); //email
//appuser.addQuery("email", "!=", "");
gs.info("in submit script 4 tostring " + app);
appuser.query();
while (appuser.next()) {
var mail = appuser.email.toString();
var name = appuser.getDisplayValue();
gs.info("in submit user email: " + mail);
gs.info("in submit user name: " + name);
email.addAddress("cc", mail, name);

}

View solution in original post

15 REPLIES 15

Hi @MPP22,

Can you try below change in your script?

user.addQuery("sys_id", app[i].toString());

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)

Sharanya Hegde3
Tera Contributor

Hi @MPP22 ,

You can try using this:

 

var user = new GlideRecord('sys_user');
user.addQuery("sys_id", 'user sys id');
user.query();
while (user.next()) {
email.addAddress('cc', user.email, user.getDisplayValue());

Mohit Kaushik
Mega Sage
Mega Sage

Hi @MPP22 ,

Are you setting something in recipients as 'TO'? If you are not doing that then with script your cc options will not appear, and the notification will not go to them. Please check for that. 'To' field should not be empty in the notification. If you are setting the values automatically, then probably you can use events to set the recipients as To and remaining things through your mail script.

Please mark this answer as correct and helpful as per the impact.  

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)

@Mohit Kaushik Yes Am setting directly in TO via Notification. In email logs can see email triggered to "TO" successfully. Issue is with "CC" dynamic email address.

MPP22
Mega Guru

Those who replied and helped were really appreciated. Thanks all for that !! @Murthy Ch @Sharanya Hegde3 @Mohit Kaushik 

 

This issue has been fixed now by referring OOB emai script "pwd.enrollment_reminder". We dont need to check array length and no need to pass array data with counter in addquery which was causing this issue (Still not sure of logic behind this). Refer to the updated piece of code for reference.

Happy Learning from mistakes !!!

 

var app = grKri.ABC.approver.split(",");
var appuser = new GlideRecord("sys_user");
appuser.addQuery("sys_id",app);
//appuser.addQuery("notification", 2); //email
//appuser.addQuery("email", "!=", "");
gs.info("in submit script 4 tostring " + app);
appuser.query();
while (appuser.next()) {
var mail = appuser.email.toString();
var name = appuser.getDisplayValue();
gs.info("in submit user email: " + mail);
gs.info("in submit user name: " + name);
email.addAddress("cc", mail, name);

}