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 pass an array into an email notification with a new line

Aditya Banka2
Tera Guru

Hello Team,

I have two arrays where I am using diff to get the difference and push it into another array as below. 

 arr_diff = arrayUtil.diff(arr1, arr);

The values comes up like this as below.

arr_diff = test1,test2,test3,test4

 

With the help of below script I am trying to keep a new line while pushing into email notification

var ritmdescription = '';

if (arr_diff.length > 0) {
for (var m = 0; m < arr_diff.length; m++) {

ritmdescription += arr_diff[m] + "\n";
}
}

I am trying to push the array values into an email notification with an event as below

gs.eventQueue("integration.test", current, ritmdescription); 

 

 

and expecting the results as 

test1

test2

test3

test4

In notification body, I kept event.parm1

 

But the end result comes up as below.

test1 test2 test3 test4

Please let me know how to add a new line after each value of the array.

1 ACCEPTED SOLUTION

Aditya Banka2
Tera Guru

Instead of loop, I used a join('<br/>') directly with diff function and that did the trick.

 

arr_diff = arrayUtil.diff(arr1, arr).join('<br/>');

View solution in original post

4 REPLIES 4

Rahul Talreja
Mega Sage

Hi Aditya,

Have you tried it using instead of loop :- 

arr_diff.join('\r\n');

 

Regards,
Rahul

Please mark my response correct/helpful as applicable!
Thanks and Regards,
Rahul

Hello Rahul,

 

It still doesn't work and printing the values in the same line.

Aditya Banka2
Tera Guru

Instead of loop, I used a join('<br/>') directly with diff function and that did the trick.

 

arr_diff = arrayUtil.diff(arr1, arr).join('<br/>');

Tejas_More_PwC
Tera Contributor

Hi,

 

I am trying to create the same using scheduled job can you share the script to check and implement the same in my instance?