CC Recipients in Email Script Triggered via Notification

Naman Jain2412
Tera Expert

I have created this email script to add the recipients in cc however it is working for custodian l4 name which is a reference field but not working for reviewers (which is list collector type) and another field u_corp_cert which is also a reference field. pls let me know the issue as script is same but not working for list collector & reference field as they are referencing to User Table

 

Here is the code 

email.addAddress('cc', current.u_custodian_l4_name.email.toString(), current.u_custodian_l4_name.getDisplayValue());
       
        email.addAddress('cc', current.reviewers.email.toString(), current.reviewers.getDisplayValue());
 
        email.addAddress('cc', current.u_corp_cert_spoc_to_ensure_document_maintenance.email.toString(), current.u_corp_cert_spoc_to_ensure_document_maintenance.getDisplayValue());

 

1 ACCEPTED SOLUTION

Samaksh Wani
Giga Sage
Giga Sage

Hello @Naman Jain2412 

if (current.reviewers) {
    var reviewersArray = current.reviewers.toString().split(',');
    for (var i = 0; i < reviewersArray.length; i++) {
        var userGr = new GlideRecord('sys_user');
        if (userGr.get(reviewersArray[i]) && userGr.email) {
            email.addAddress('cc', userGr.email.toString(), userGr.getDisplayValue());
        }
    }
}

 

Use the above code for reviewers. The reason behind the failure of code is -

 

 

  • This is a multi-value field that contains multiple users, stored as a comma-separated list of sys_ids — not GlideRecord references.

  • So current.reviewers.email won’t work — because reviewers is not a single record.

Pls mark my solution as accept and thumbs up if you find it helpful. It will help other users on community to find helpful response.

 

Regards,

Samaksh Wani

 

View solution in original post

2 REPLIES 2

Shruti
Mega Sage
Mega Sage

Hi,

For list fields, add a for loop

var reviewers = current.reviewers.toString().split(','); // Get sys_ids as an array
for (var i = 0; i < reviewers.length; i++) {
    var userGR = new GlideRecord('sys_user');
    if (userGR.get(reviewers[i])) {
        email.addAddress('cc', userGR.email, userGR.getDisplayValue());
    }
}

Samaksh Wani
Giga Sage
Giga Sage

Hello @Naman Jain2412 

if (current.reviewers) {
    var reviewersArray = current.reviewers.toString().split(',');
    for (var i = 0; i < reviewersArray.length; i++) {
        var userGr = new GlideRecord('sys_user');
        if (userGr.get(reviewersArray[i]) && userGr.email) {
            email.addAddress('cc', userGr.email.toString(), userGr.getDisplayValue());
        }
    }
}

 

Use the above code for reviewers. The reason behind the failure of code is -

 

 

  • This is a multi-value field that contains multiple users, stored as a comma-separated list of sys_ids — not GlideRecord references.

  • So current.reviewers.email won’t work — because reviewers is not a single record.

Pls mark my solution as accept and thumbs up if you find it helpful. It will help other users on community to find helpful response.

 

Regards,

Samaksh Wani