Concatenation of string having line breaks(\n)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2017 12:56 PM
Hi All,
I want to write a fix script to concatenate string having line breaks(\n) with space in-between. Please find the example below :
I want the above comments field to be updated as "abcd efgh ijkl mnop".
I have written a fix script which looks like below:
var gr = new GlideRecord("alm_hardware");
gr.addQuery('display_name','P1000479 - Apple MacBook Pro 15"'); //As of now testing for one record
gr.query();
while (gr.next()) {
gr.comments = gr.comments.replace(/\n/g, " ");
gs.log("check" + gr.comments);
gr.update();
}
But the above script is just adding a space in front of the string and not concatinating.
can anyone help me on this.
Thanks,
Neha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2017 02:15 PM
try use this instead:
gr.comments = gr.comments.replace(/(\r\n|\n|\r)/gm,"")
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-04-2017 01:36 AM
Hi Goran,
Thanks for the response. It worked as expected . I do not find the option to mark it correct hence marking it helpful.
Thanks again.
Thanks,
Neha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-04-2017 04:19 AM
Perfect 😃
Strange, you should have a big "correct answer" at my reply to the left.. but most important that it worked 😃
//Göran