The CreatorCon Call for Content is officially open! Get started here.

Event parameter and Notification email

PhoenixMing0912
Giga Expert

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

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

AbhishekGardade
Giga Sage

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:

  1. Create an event in Event Registry. let’s say changes on incident table
  2. Create a business rule with Run conditions. Let’s say assigned to Changes
  3. 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);

  1. 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);

  1. Create/ Modify your notification as below:find_real_file.pngfind_real_file.png
  2. 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

Thank you,
Abhishek Gardade

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

Thank you,
Abhishek Gardade