How to set dynamic recipient to the email notification using email scripts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2023 02:56 AM
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,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2023 04:44 AM
Hi @BharathChintala ,
It didn't work.
logs are giving me correct values but still email is not being sent as I can't see email in email logs.
below is the email script:
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);
gs.log('asset received2' + userGR);
var Useremail = userGR.getValue('email');
gs.log('asset received3' + Useremail);
var UserName = userGR.getValue('name');
gs.log('asset received4' + UserName);
email.addAddress('to', Useremail, UserName);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2024 01:16 AM
email.setReplyTo(Useremail)
function will not work. It will provide the right logs but email will not be triggered. Along with this a Business Rule is required to be triggered, with the function gs.eventqueue() where the recipient's are given ,for this we have to select "when the event is fired" in the notification.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2025 09:43 AM
email.addAddress only works for "cc" and "bcc"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2025 08:05 AM
I have faced similar issue for email notification where I was not able to send multiple values in TO field, try using business rules , here is the article reference :Setup email notification using Business rule.
Please mark this answer helpful, if it has solved your problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2025 10:31 AM
@Yash38 You need to use gs.eventQueue('event_name',glide_object,parm1,parm2);
Parm1-collect all the sys Ids of the users you want to send reply to, save them in arrays and convert it to string and the fourth parameter can be left as empty string ''.
You need some trigger point say may be Business rules to call eventQueue from it.
Mark my response helpful if it helped you.
Thanks,
Mahesh.