How to send notification to multiple email ID's of a same person.

Ashwini8
Tera Contributor

Hi All,

We have a requirement that when a notification is sent, suppose a user has 2 mail id's. then it should send the notification to both the email address.

In user form we have below fields, suppose alternative email id field is not empty then it should send notification to both the email id's. Please suggest some solution to implement this.

find_real_file.png

Thanks

1 ACCEPTED SOLUTION

Rogers Cadenhe1
Giga Guru

Create a business rule on sys_email before insert that adds each recipient's alternate email address to the Recipients field.

(function executeRule(current, previous /*null when async*/) {

	// get the current recipient(s)
	var emailTo = current.recipients.split(',');
	for (var i = 0; i < emailTo.length; i++) {
		// look for a user matching a recipient email address
		var userRec = new GlideRecord('sys_user');
		userRec.addEncodedQuery('email=' + emailTo[i] + '^u_alternate_emailISNOTEMPTY');
		userRec.query();
		if (userRec.next()) {
			// found one, so add their alternate email
			emailTo.push(userRec.u_alternate_email);
		}
	}
	// save the recipients
	current.recipients = emailTo.join(',');

})(current, previous);

View solution in original post

20 REPLIES 20

Okay.

So in the mail script, assuming you want to fetch the assigned_to user primary and alternate meails.. do like this

1. In place of assigned_to, put your field. and also use right field names of your priamry and alternate email.

email.addAddress("cc",current.assigned_to.primary_email,current.assigned_to.getDisplayValue());
email.addAddress("cc",current.assigned_to.alternate_email,current.assigned_to.getDisplayValue());

and call this mail script in your notification 

${mail_script:your_mailscript_name}

2. In the notifcation, under receipients, ensure you select atleast 1 recipient.

Hi Asif,

Yes I tried this method. I selected my name and i have 2 email id's. There is also 1 group we added. Still the code is not working its sending only to primary email id. I am not getting what is the reason its not triggering. Can you please suggest

Hi,

can you share yoru notification screenshots.

Hemant Goldar
Mega Sage
Mega Sage

Hi Ashwini,

 

Here my caller have two email address field  1)email 2)alternate email.

so configured as below and notification gets triggering to both email ID. 

find_real_file.png

 

Please find the below link it will help to add CC and BCC.

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

 

I hope it helps,

 

Thanks,

Hemant

For me I am getting only caller option no + symbol. PFB screen shot.

find_real_file.png