how to add members in email cc?

priyankmish
Tera Contributor

 i have created below email script and using this in the email Message HTML ,  but not able to see the added members in the cc , can anyone please help me with this?

1 ACCEPTED SOLUTION

Laveena-Agarwal
Mega Sage

Hi @priyankmish 

 

  • Your script looks good to me if you are calling this in notifications, but it requires validation for all the values. If any of the values where you have applied dot-walking are undefined/null, the script won’t work.  

Look at this video, here it is explained to apply validations-

https://www.youtube.com/watch?v=2k7szQymVBM

 

  • Another possible reason — if you have any value configured in the property: glide.email.test.user
    then the notification may not work as expected for CC/BCC.

ServiceNow Article :- https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0783517

 

 

View solution in original post

4 REPLIES 4

Tanushree Maiti
Kilo Patron

Hi @priyankmish 

 

Add gs.log and check whether you dot walking field showing you to correct value

Sample code:

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */ event) {
 var groupMembers = new GlideRecord('sys_user_grmember');
    groupMembers.addQuery('group.name', 'Group A');  //Query it as per your requirement
    groupMembers.addEncodedQuery('user.emailISNOTEMPTY'); 
    groupMembers.query();
    while (groupMembers.next()) {
        var userEmail = groupMembers.user.email; 
        var userName = groupMembers.user.getDisplayValue(); 
        if (userEmail) {
             email.addAddress('cc', userEmail, userName); 
        } else {
            gs.log("User " + userName + " does not have a valid email address.");
        }
    }

 

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

I have verified this using a background script, where I was able to retrieve all email addresses. Also, both the notification and the mail script belong to the sn_retail scope.

Laveena-Agarwal
Mega Sage

Hi @priyankmish 

 

  • Your script looks good to me if you are calling this in notifications, but it requires validation for all the values. If any of the values where you have applied dot-walking are undefined/null, the script won’t work.  

Look at this video, here it is explained to apply validations-

https://www.youtube.com/watch?v=2k7szQymVBM

 

  • Another possible reason — if you have any value configured in the property: glide.email.test.user
    then the notification may not work as expected for CC/BCC.

ServiceNow Article :- https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0783517

 

 

Ankur Bawiskar
Tera Patron

@priyankmish 

share script here and not image for script

Also what debugging did you do from your side?

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