- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2021 10:21 PM
Hi,
I want to create a mail script and it should be called from email template. How can I achieve getting different outputs from same mail script dynamically. Can we achieve this by passing through any parameters in the email scripts. Is there any mechanism to pass parameters to mail script from email template. At present for every variable I am creating a unique mail script to get the value Is there any way to get the variables dynamically from a single mail script i.e called from email template.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2021 02:31 AM
Hi,
You cannot pass any parameter etc to email script unless you are triggering the notification via eventQueue
3rd or 4th parameter you can use to send some data
gs.eventQueue('event_name', obj, 'my-data','');
Then access the data in email script using event.parm1
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2021 10:48 PM
Hi,
are you referring to email template means from the email client?
please share some details
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2021 10:58 PM
Hi Ankur,
I want to call that mail script from email template created by me and used in the notification.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2021 11:05 PM
Hi,
You can call the email script from email template.
If you wish to have different message when the same email script is called from Notification 1, Notification 2 then you can use this
I shared solution here
How to send different notifications to different users through email script
In the email notification mail script you will have to determine which is the current notification which invoked this email script and based on that set the users
(function runMailScript(current, template, email, email_action, event) {
// Add your code here
var notificationName = email_action.name; // get the notification name
if(notificationName == 'Name of Notification 1'){
// content 1
}
else if(notificationName == 'Name of Notification 2'){
// content 2
}
else if(notificationName == 'Name of Notification 3'){
// content 3
}
})(current, template, email, email_action, event);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2021 12:42 AM
Hi Ankur,
I want to call this from same notification. But I want to get different variables dynamically based on any condition. For example if I want only assignment group it should be returned. If I want assigned to it also should be returned from same mail script.