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

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);

Thanks, Its working as expected.

This code will work for all outgoing notifications. Is that what you want?

Yes

Hi Rogers,

Here we need to add the condition like "Type is send-ready and Alternate email IsNotEmpty". If i add this condition the notification is not triggering. Can you please help how can we achive this?