- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2022 04:29 AM
Dear All,
I have a requirement, there is list field on the form and added 4 users in that list field. An email notification has to be sent to the 4 users by addressing their names individually as Dear "X", Dear "Y", Dear "Z".
Not all 4 names in one email, it has to be separated. Dear "X" should get email by addressing his/her name alone.
How can I achieve it?
Solved! Go to Solution.
- Labels:
-
Script Debugger
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2022 06:49 AM
Hi,
Please follow the steps below to achieve your requirement:
1) Create a Event by navigating to Registry module as shown below and create a event:
For example I have done this for Catalog Task table but you can change it to the Table on which your List field is present.
2) Now create a After Update Business Rule on your table where the List field is present and use the script below:
Script to be used:
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var getListusers = current.watch_list; // Replace "watch_list" with your field name
var splitusers = getListusers.split(',');
for(var i=0;i<splitusers.length;i++){
gs.eventQueue('send.email.task',current,splitusers[i]); // Replace "send.email.task" with the Event which you created.
}
})(current, previous);
Make Sure to add a condition to the BR as below so that this BR does not run all the time:
Field Changes For example Watch List Changes
3) Now create a Notification email script and use the code below:
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
// Add your code here
var gr = new GlideRecord('sys_user');
gr.get(event.parm1);
template.print(gr.name);
})(current, template, email, email_action, event);
3) Now Navigate to your Notifications module and select the trigger as Event based and select the event which you have configured in step 1
Also make sure to select "Parm1" and "Send to Event Creator" checkbox as True as shown below:
In the Body of the email, you need to call the Notification Script created in above step:
${mail_script:Name of your Email Script}
For example ${mail_script:getRecipientName} // getRecipientName is the name of my Email Script
Result:
I Have updated my ticket to update Watch list field with two users "System Administrator and Abel Tuter" and below are the email which got triggered with individual names:
\
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2022 04:41 AM
Hello Udhya,
var arr = [];
var arr1 = [];
var arrayUtil = new ArrayUtil();
if(arrayUtil.contains(arr1,current.u_field_name.toString()))
{
continue;
}
arr1.push(current.u_field_name.toString());
for (var i = 0; i < arr1.length; i++)
{
gs.eventQueue('eventname',current,current.sys_id,arr1[i]);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2022 04:56 AM
Hi,
You cannot set dynamic body consents for different users when they are in to/cc list of same email.
If you want to send user specific email then you need to make it event bases and trigger event 4 times and populate the name of user who is going to receive this email.
If all users are in to/cc list then you cannot set user name dynamically.
You can consider an example when you send mail to your team from your mail box. If we are sending an email to team then we do not mention name. because it is generic message, same is with ServiceNow.
If you want to include each user name then you need to send an individual email.
Thanks
Anil Lande
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2022 06:49 AM
Hi,
Please follow the steps below to achieve your requirement:
1) Create a Event by navigating to Registry module as shown below and create a event:
For example I have done this for Catalog Task table but you can change it to the Table on which your List field is present.
2) Now create a After Update Business Rule on your table where the List field is present and use the script below:
Script to be used:
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var getListusers = current.watch_list; // Replace "watch_list" with your field name
var splitusers = getListusers.split(',');
for(var i=0;i<splitusers.length;i++){
gs.eventQueue('send.email.task',current,splitusers[i]); // Replace "send.email.task" with the Event which you created.
}
})(current, previous);
Make Sure to add a condition to the BR as below so that this BR does not run all the time:
Field Changes For example Watch List Changes
3) Now create a Notification email script and use the code below:
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
// Add your code here
var gr = new GlideRecord('sys_user');
gr.get(event.parm1);
template.print(gr.name);
})(current, template, email, email_action, event);
3) Now Navigate to your Notifications module and select the trigger as Event based and select the event which you have configured in step 1
Also make sure to select "Parm1" and "Send to Event Creator" checkbox as True as shown below:
In the Body of the email, you need to call the Notification Script created in above step:
${mail_script:Name of your Email Script}
For example ${mail_script:getRecipientName} // getRecipientName is the name of my Email Script
Result:
I Have updated my ticket to update Watch list field with two users "System Administrator and Abel Tuter" and below are the email which got triggered with individual names:
\
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.