Ho to break line (new line) from a string.

sinu2
Tera Expert

Hi All,

 

I have one string where i stored glide record information like this Name1:Value1,Name2:Value2,Name3:Value3,Name4:Value4 . But here the client gets more confusion like that so that i want

 Name1:Value1,

Name2:Value2,

Name3:Value3,

Name4:Value4

Please find the below script which i wrote.

state_report= sr.u_productnumber+ ':' +sr.u_hpprodfamily+  ','  +state_report;

 

Can anyone help on this.

1 ACCEPTED SOLUTION

Hi,

Use below script; instead of \n I have used two spaces

state_report= sr.u_productnumber+ ':' +sr.u_hpprodfamily+  ','  + '  ' + state_report;

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

11 REPLIES 11

Hi Morris,

 

can  you help on this 

@Kindly help on the  scenario

 for the same i want space like this ..Just i need double space in between every item like below.

 

Name1:Value1,  Name2:Value2,  Name3:Value3,  Name4:Value4

 

what needs to be done?

Hi,

Use below script; instead of \n I have used two spaces

state_report= sr.u_productnumber+ ':' +sr.u_hpprodfamily+  ','  + '  ' + state_report;

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

The SN Nerd
Giga Sage
Giga Sage

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

ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

How can we achieve it in showFieldMsg().

Anand14
Kilo Explorer

Hi,

I want to make the u_bood_cd and Related data in the next like but it doesn't work for me if i try "\n" 

Code:

kb.text = current.close_notes + "\n" + kb.u_bood_cd + "\n" + "\n" + 'Releated Data : ' + current.comments.getHTMLValue();

result : 

Program change has been completed.  Releated Data :


25/09/2020 06:40:56 -  Additional comments