How to set dynamic recipient to the email notification using email scripts

Yash38
Kilo Guru

Here is the code I'm using to set the recipient of an email notification as the variable on catalog task form using email script:

 

This log: gs.log('asset received3' +Useremail); is giving the correct value but still the notification is not being sent to this user instead it is getting sent to the request_for variable which i have selected in who will receive tab on notification page.

 

 

var taskGR = new GlideRecord('sc_task');
taskGR.get(current.sys_id);

var recipient = current.variables.asset_assigned_to_user;
gs.log('asset received' +recipient);
var userGR = new GlideRecord('sys_user');
userGR.get(recipient);
//current.variables.recipient = userGR.getValue('email');

var Useremail = userGR.getValue('email');
gs.log('asset received3' +Useremail);

email.setReplyTo(Useremail);

 

What could possibly go wrong here.

 

Thank in advance

 

Regards,

9 REPLIES 9

BharathChintala
Mega Sage

@Yash38 use this in last line

 

email.addAddress("to", userGR.email,userGR.name);
If my inputs have helped with your question, please mark my answer as accepted solution, and give a thumb up.
Bharath Chintala

Hi @BharathChintala ,

It's not working.

logs are giving me the email id of the desired user but somehow email is not being sent.

@Yash38 Can you send screenshots of notification and script

 

If my inputs have helped with your question, please mark my answer as accepted solution, and give a thumb up.
Bharath Chintala

@Yash38 Did you call email script in body only write

${mail_script:ScriptName}
in above format

If my inputs have helped with your question, please mark my answer as accepted solution, and give a thumb up.
Bharath Chintala