send notification to users in related list

IceIronDragon
Tera Guru

Hello All,

 

We have a requirement where in notifications should go to all the affected users in the related list not just one in the Affected user field on the form.Whats happening right now is the notification is only being sent to the person in affected user field, not for multiple users in the related list

 

IceIronDragon_0-1669132917546.png

 

IceIronDragon_1-1669132955271.png

 

 

1 ACCEPTED SOLUTION

use below script in mail script. Glide Proper table which is present on related list and field names.

 var gr = new GlideRecord("Related list table Name");
    gr.addQuery("task", current.sys_id);
    gr.query();
    while (gr.next()) {
        email.addAddress("cc", gr.user.email, gr.name);
    }

Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

View solution in original post

11 REPLIES 11

Yes. 

If you want the dynamic affected users list then you will have to use that. To get the users list.


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

Thank you Gunjan for the insight , could you help me with a sample script here ?

use below script in mail script. Glide Proper table which is present on related list and field names.

 var gr = new GlideRecord("Related list table Name");
    gr.addQuery("task", current.sys_id);
    gr.query();
    while (gr.next()) {
        email.addAddress("cc", gr.user.email, gr.name);
    }

Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

gunjanm,

 

thank you for the response.  

I have configured the email script as mentioned and created a simple notification. It is still sending notification to 1 affected user. I cannot fathom what am I missing here.

 

IceIronDragon_0-1669230631138.png

IceIronDragon_1-1669230665141.pngIceIronDragon_2-1669230723436.png

 

bravosa
Kilo Guru

You can create an email script and add it to your notifications

 

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

	// Add your code here
	if(event.user_id=='system'){
			var user = new GlideRecord("m2m_table");
			user.addQuery("parent",current.getUniqueValue());
			user.query();
			while(user.next()){
				email.addAddress("bcc",user.getValue('email_address'),user.getValue('name'));
			}
	}
	
})(current, template, email, email_action, event);