Notification email script to add related team members

Nishant16
Tera Expert

Need to add the recipients of Account team members of a case with Responsibility definition of "Account Manager" to the outgoing emails for a case, I tried the below email script but not working.
can someone help me please.

Below is the email script

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {

          // Add your code here
	
    var groupMembers = new GlideRecord('sn_customerservice_team_member');
    groupMembers.addQuery('account', current.account.sys_id);
    groupMembers.addEncodedQuery('responsibility=d151dbgeddbt654d49d2dce46ld786fg3'); //Responsibility is Account Manager
    groupMembers.query();
    while (groupMembers.next()) {
			email.addAddress("cc",  groupMembers.user.email, groupMembers.user.getDisplayValue());
        }

})(current, template, email, email_action, event);

 

1 ACCEPTED SOLUTION

Good catch on the suggestion with the Group, that should eliminate the scripting need. Probably.

 

Also, I'm assuming the sn_customerservice_team_member table is a M2M table.

So the suggestion with getDisplayValue will not work, unless you make some modifications.

First you'll need to get that record.

Something like this:

 while (groupMembers.next()) {
        var userGR = groupMembers.user.getRefRecord();
	email.addAddress("cc",  groupMembers.user.email.toString(), userGR.getDisplayValue());
 }

 

View solution in original post

5 REPLIES 5

OlaN
Giga Sage
Giga Sage

Hi,

Can you explain in more detail what the issue is?

Does not query not work/not return any results?

Does the attaching of CC to the email not work?

Hi Olan, 

Query is returning the result, but unable to attach the user to cc

Try changing the second parameter to this:

groupMembers.user.email.toString()

ricker
Tera Guru

Nishant16,

Why don't you send the notification to the group? No script needed.

 

Also your syntax is wrong on groupMembers.user.getDisplayValue();

it should be groupMembers.getDisplayValue('user');