Event parameter and Notification email
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2019 10:25 PM
Hi all,
I have registered an event and my notifiation would be triggered by the event.
As known, event has two parameters, these two parameters can be used in notification e-mail template.
My question is, if there are more than two paramters I want to pass, how can I do that?
Is it possible that a parameters is a JSON object and it can be parsed somewhere and use its attributes or fields in e-mail template as variables.
Regards,
Ming
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2019 10:43 PM
Hi Phoenix,
yes that is possible; you can send whatever in the event parameter
it could be an array, or json string etc
in the email script you can access the event parameter as below and then parse it
var jsonString = event.parm1;
If you want to send more than 2 parameters then in one of the parameter add a separator symbol such as @ or # and then in email script split using this symbol and you can get the values
gs.eventQueue('eventName', current, 'hello@abc');
var combinedValues = event.parm1;
var value1 = combinedValues.split('@')[0];
var value2 = combinedValues.split('@')[1];
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
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
10-29-2019 10:43 PM
Hello Ming,
Its Possible, you can create a JSON Object and sent it to eventQueue. With help of Email script or template you can parse that JSON Object.
Steps are given Below:
- Create an event in Event Registry. let’s say changes on incident table
- Create a business rule with Run conditions. Let’s say assigned to Changes
- Add Below code in your business rule
(function executeRule(current, previous /*null when async*/) {
// sending json in event:
var obj =
{
“newAssingedto”: previous.assigned_to.toString() ,
“oldAssingedto” : previous.assigned_toString();
};
Var json = JSON.stringify(obj);
gs.eventQueue(‘assignedTo.changes’, current, json);
s})(current, previous);
- Create a new mail Script in Notification Email Scripts module and add following code.
Name: assignedTo.changes
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
var jsonObject = JSON.parse(event.parm1);
template.print('New Assigned to: '+ jsonObject. newAssingedto);
template.print('Previous Assigned to: '+ jsonObject. oldAssingedtos);
})(current, template, email, email_action, event);
- Create/ Modify your notification as below:
- As you can see in above image, You can call email script in notification and with this syntax:
${mail_script:”name of the mail script”}
Please mark as Correct Answer and Helpful, if applicable.
Thanks!
Abhishek Gardade
Hexaware Technologies
Abhishek Gardade
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2019 01:35 AM
Any updates on this?
Can you please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.
Thanks!
Abhishek Gardade
Abhishek Gardade