How to break line (new line) from a string

Joshuu
Kilo Sage

Hi all/ @

 

I have one string where I have stored glide record information like this 1. Jack Hawksworth 2. Kyle Toon 3. Mario Sever 4. Nikola Pintaric . 

 

But we would like to change it as below

1. Jack Hawksworth

2. Kyle Toon

3. Mario Sever

4. Nikola Pintaric 

 

Please find the below script which I wrote.

tech_contacts = tech_contacts + techGr.u_sequence + '. ' + techGr.getDisplayValue('u_tech_contact') + '\n';

return JSON.stringify({
"tech_contact": tech_contacts,

});

 

Can anyone help me on this.

 

Thanks,

Priya.

1 REPLY 1

BharathChintala
Mega Sage

@Joshuu 

Follow this general pattern to print data in new lines

  1. Create an array
  2. Push each new line to the array
  3. Use .join("\n") on array
  4. Store results

Example

//Create Array
var description = [];

//Push each new line to array
description.push("Short Description: " + current.short_description);
description.push("Assignment Group: " + current.assignment_group.getDisplayValue());
description.push("Category: " + current.category.getDisplayValue());

//Use join("\n")
var results = description.join("\n");

//Store results
current.description = results;

 Result

Short Description: Issue with computer
Assignment Group: Service Desk
Category: PC

 Thanks,

Bharath

If my inputs have helped with your question, please mark my answer as accepted solution, and give a thumb up.
Bharath Chintala