Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

how to trigger notification Keeping Set of users or full users from group as CC in email notificatio

lakshmi_laksh
Tera Contributor

Hello,

I have a requirement, i need to send notification to all users of a particular group as CC.
anyone can help me on this
thanks in advance.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@lakshmi_laksh 

you will have to use email script and then iterate over sys_user_grmember table and use this line

email.addAddress("cc", "email", "name");

something like this

(function runMailScript(current, template, email, email_action, event) {

    // Add your code here
    var gr = new GlideRecord("sys_user_grmember");
    gr.addQuery("group.name", "Group ABC");
    gr.query();
    while (gr.next()) {
        email.addAddress("cc", gr.user.email.toString(), gr.user.getDisplayValue());
    }

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

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

5 REPLIES 5

SumanthDosapati
Mega Sage
Mega Sage

@lakshmi_laksh 

 

You can write below script to get the users email addresses from a group and add them to cc

var emails = [];
var grMem = new GlideRecord('sys_user_grmember');
grMem.addQuery('sys_id', 'giveyourgroupsysidhere');
grMem.query();
while(grMem.next())
{
	email.addAddress("cc", grMem.user.email, grMem.user.getDisplayValue());
}

 

Accept the solution and mark as helpful if it does, to benefit future readers.
Regards,
Sumanth