How to email email to all Group member in CC. in email Notification template .Please tell email script

Sadashiva Das1
Tera Contributor

How to send email to  all Group member in CC. in email Notification .Please tell the Email script for that .

Please suggest .

 

 

6 REPLIES 6

Voona Rohila
Kilo Patron
Kilo Patron

Use this in your email script and include in your notification.

//email.addAddress(type, address, displayname);
email.addAddress("cc","group@example.com","group name");

check below link

https://docs.servicenow.com/bundle/quebec-servicenow-platform/page/script/server-scripting/reference...

Check below link on how to include email Script in notification

https://developer.servicenow.com/dev.do#!/learn/learning-plans/quebec/new_to_servicenow/app_store_le...


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

Ankur Bawiskar
Tera Patron
Tera Patron

@Sadashiva Das 

you need to use email script and include that email script in the email body

${mail_script:addCCUsers}

Mail Script

Name: addCCUsers

Script:

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

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

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

If your notification is on the table which holds group then update the query as this

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

Regards
Ankur

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

@Sadashiva Das 

Thank you for marking my response as helpful.

If my response helped you please mark it correct to close the question so that it benefits future readers as well.

Regards
Ankur

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

@Sadashiva Das 

Thank you for marking my response as helpful.

If my response helped you please mark it correct to close the question so that it benefits future readers as well.

Regards
Ankur

 

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