Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to send multiple values to notification using gs.eventQueue()

dev115415
Tera Expert

Hello

I want to send multiple values like 8 to 10 values from my script include to email body of Notifications. I am using event triggering based approach. How to send this.

2 ACCEPTED SOLUTIONS

Weird
Mega Sage

What type of values?
One example would be to create a JSON object, send that and handle the values in email script.

For example:

obj = {};
obj.value1 = "value1";
obj.value2 = "value";
objString = JSON.stringify(obj);

gs.eventQueue('event_name, current, objString, "");

In your event you pass the objString and then in the email script you can parse it as:

var obj = JSON.parse(event.parm1);
//Then you can either loop it or access the values how you want.

for(var i in obj){
template.print(obj[i]);
}

//or
template.print(obj.value1);

View solution in original post

Community Alums
Not applicable

Hello, 

In notification -> What it will contain section, you can make use of mail script like this

Brunda_0-1685953505804.png

And you can create the email script to fetch the values from the object

Brunda_1-1685953617670.png

 

If my response resolves your issue please mark correct or helpful. 

Thank you

View solution in original post

7 REPLIES 7

Weird
Mega Sage

What type of values?
One example would be to create a JSON object, send that and handle the values in email script.

For example:

obj = {};
obj.value1 = "value1";
obj.value2 = "value";
objString = JSON.stringify(obj);

gs.eventQueue('event_name, current, objString, "");

In your event you pass the objString and then in the email script you can parse it as:

var obj = JSON.parse(event.parm1);
//Then you can either loop it or access the values how you want.

for(var i in obj){
template.print(obj[i]);
}

//or
template.print(obj.value1);

@Weird Thank you for your approach. I created a list say of fruits in my script include. 

var list1 = ['Mango', 'Grapes', 'Pomegranate'];
var sendList1 = JSON.stringify(list1);

gs.eventQueue('x_1043123_needlt.eventForSendingMail', current, sendList1, '');

 

Now I want to know how to fetch this value in my "What it will contain" section in Notification.

Where to write 

var obj = JSON.parse(event.parm1);

 

dev115415_0-1685948744479.png

 

dev115415_1-1685948774214.png

 

Community Alums
Not applicable

Hello, 

In notification -> What it will contain section, you can make use of mail script like this

Brunda_0-1685953505804.png

And you can create the email script to fetch the values from the object

Brunda_1-1685953617670.png

 

If my response resolves your issue please mark correct or helpful. 

Thank you

Thankyou @Community Alums  This worked. One more help how to insert a new line in template.