cc people in group

brendanwilson84
Kilo Guru

Hi guys

I have a requirement to send a cc notification to people in a group, the group of people could change depending on what is selected for example assignment group

find_real_file.png

There is currently two people in this group. If I change the assignment group and use another, they could be 2 different people.

I have done a mail script as follows but doesn't seem to be working. I don't have much experience in scripting or coding and would appreciate any advice or help on were I am going wrong.

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,  
                  /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,  
                  /* Optional GlideRecord */ event) {  
email.addAddress("cc",current.assignment_group,current.assignment_group.name);

     

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

6 REPLIES 6

amaradiswamy
Kilo Sage

Hi Wilson,



If you are sending notification from workflow, then in mail script, try some thing below


<mail_script>


email.addAddress("cc", current.variables.variable_name.email, current.variables.assignment_group.getDisplayValue());


</mail_script>



if you are trying to send a notification, when record was created in a table, then you can define a notification on the table and select assignment group in users/groups in fields.




Thanks and regards,


Swamy


Deepa Srivastav
Kilo Sage

You have to take all members of the group and put this code in loop. If more than one member is there cc will not work this way.


Re: Adding CC in email notification from event parameter


Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.


brendanwilson84
Kilo Guru

thank you all.



Got it working, it is not coming from a workflow and this is the code that worked



var grp = new GlideRecord("sys_user_grmember");


grp.addQuery("group", current.assignment_group);


grp.query();


while(grp.next()) {


var userid = grp.user;


var user = new GlideRecord("sys_user");


user.addQuery("sys_id",userid);


user.query();


while (user.next()) {


email.addAddress("cc", user.email, user.getDisplayValue());


  }


  }


Sailesh4
Giga Expert

Hi Guys,

This probably might be an old post. I was just checking for the similar one, and couldn't find the relevant code. Below is what I have written and it worked perfectly for me.

var a = new GlideRecord('sys_user_grmember');
a.addQuery('group', current.assignment_group);
a.query();
while (a.next()) {
    email.addAddress("cc", a.user.email, a.user.name);
}

If it works for you please mark it as closed and complete the loop.

Thanks,
Sailesh