How to set/popup an arrays values in new lines using g_form.addInfoMessage?

Virendra K
Kilo Sage

Hi All,

 

I am returning an array from script include to Onchange client script where I need to popup it using g_form.addinfomessage, but its showing in one line.

I want to show each value in a separate line. like

Info:

ABC

XYZ

LMN

 

I used '\n', but no luck.

 

How to show array values in a separate new lines?

 

Thanks,

Virendra

1 ACCEPTED SOLUTION

Isaac Vicentini
Mega Sage
Mega Sage

Hi @Virendra K,

 

You can do this in two ways:

 

1. Join the array values ​​with <br/> to insert line breaks between each value:

 

// Assuming you're getting an array from the Script Include
var myArray = ['ABC', 'XYZ', 'LMN'];

// Join the array values with a line break
var message = 'Info:<br/>' + myArray.join('<br/>');

// Display the message with each value on a new line
g_form.addInfoMessage(message);

 

 

2. Using for each, to separate lines:

 

// Assuming you have the array returned from Script Include
var myArray = ['ABC', 'XYZ', 'LMN'];

// Initialize the message with the desired text
var message = 'Info:<br/>';

// Add each array value to a new line
myArray.forEach(function(item) {
    message += item + '<br/>';
});

// Displays the formatted message
g_form.addInfoMessage(message);

 

 


 

If my answer helped you in any way, please mark it as correct/helpful 🙂

Regards,

Isaac Vicentini.

 




Best regards,

Isaac Vicentini
MVP 2025


If my answer was helpful, mark it as Helpful or Accept as Solution.

View solution in original post

2 REPLIES 2

Ganesh Palve
Tera Expert

1.test your output of SI using alert(); where you use '\n'

 

Isaac Vicentini
Mega Sage
Mega Sage

Hi @Virendra K,

 

You can do this in two ways:

 

1. Join the array values ​​with <br/> to insert line breaks between each value:

 

// Assuming you're getting an array from the Script Include
var myArray = ['ABC', 'XYZ', 'LMN'];

// Join the array values with a line break
var message = 'Info:<br/>' + myArray.join('<br/>');

// Display the message with each value on a new line
g_form.addInfoMessage(message);

 

 

2. Using for each, to separate lines:

 

// Assuming you have the array returned from Script Include
var myArray = ['ABC', 'XYZ', 'LMN'];

// Initialize the message with the desired text
var message = 'Info:<br/>';

// Add each array value to a new line
myArray.forEach(function(item) {
    message += item + '<br/>';
});

// Displays the formatted message
g_form.addInfoMessage(message);

 

 


 

If my answer helped you in any way, please mark it as correct/helpful 🙂

Regards,

Isaac Vicentini.

 




Best regards,

Isaac Vicentini
MVP 2025


If my answer was helpful, mark it as Helpful or Accept as Solution.