how-to-concatenate-text-from-multiple-rows-into-a-single-text-string in service now using jelly or glide record

Shilpi Sharma2
Tera Contributor

how-to-concatenate-text-from-multiple-rows-into-a-single-text-string in service now using jelly or glide record  For Example i have a name field in my table having 2 records one is shilpi and second in arti  i want to display output as "shilpi,Arti". Please help urgently as i am novice developer and give proper example

1 ACCEPTED SOLUTION

benjamin_alldri
Mega Expert

Your easiest bet would be to use GlideRecord and then use a simple array and join, like so:

// Define our array to push onto
var concatString = [];

// Initialise GlideRecord and get the results
var gr = new GlideRecord('table');
gr.query();

// Step through the results
while(gr.next()) {

	// Push the string value of our name onto the array stack
	concatString.push(gr.name.toString());
}

// Join the array values together with a comma
concatString.join();

 

 That will step through all records returned, push the string value of name onto the array, and then join them with a comma.

View solution in original post

3 REPLIES 3

benjamin_alldri
Mega Expert

Your easiest bet would be to use GlideRecord and then use a simple array and join, like so:

// Define our array to push onto
var concatString = [];

// Initialise GlideRecord and get the results
var gr = new GlideRecord('table');
gr.query();

// Step through the results
while(gr.next()) {

	// Push the string value of our name onto the array stack
	concatString.push(gr.name.toString());
}

// Join the array values together with a comma
concatString.join();

 

 That will step through all records returned, push the string value of name onto the array, and then join them with a comma.

Thanks benjamin.alldridge your answer really help me lot

 

Ct111
Tera Sage

Hi Shilpi,

 

You can use below sample and make changes to your code in Jelly like this 

 

  <td>LOCKER</td>                                             //Suppose field name is LOCKER           

<td>${jvar_gr.getDisplayValue('u_a')}             // field LOCKER is made up of field "a" and field "b"

${jvar_gr.getDisplayValue('u_b')}

</td>

 

THEN you can get values of both fields and put like above

 

 

And in case of GLIDE record

 

var gr = new GlideRecord('sample_table');

gr.addQuery('active', true);

gr.query();

while(gr.next())

{

 

gr.u_LOCKER = gr.u_a + '' +gr.u_b;

 

}

The above glide record queries "sample table" , pulls up all active records and concate the values of "a" and "b"  and assign it to LOCKER field for all those records that had active as true