How to remove line breakers from from multi line text field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2025 09:34 PM
below code is not working to remove line breakers on Description field. could someone help me to find out the issue.
On Description field is updated with - xcgfchfg\r\n\r\ngdfhgfjfhj\r\n\r\n\r\nfdhfkghjkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk\r\ndhgdh\r\n\r\n\r\n\r\n\r\n\r\nfdhfffffffffffffffffff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2025 11:12 PM
your script looks fine and it worked for me
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2025 02:47 AM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2025 01:55 AM
Hello @venkram
I agree with @Ankur Bawiskar . When we directly add the test string, it works as expected. The issue arises when retrieving the value from the short description, where it doesn't behave as anticipated.
To resolve this, I first encoded the string and then replaced the encoded values for \n and \r (%255Cn and %255Cr) with an empty string.
You can try the following script:
var gr = new GlideRecord('cmdb_ci_ip_firewall');
gr.addQuery('name', 'Test01'); // Correct query for the record
gr.query();
if (gr.next()) {
var desc = gr.getValue('short_description');
var encodedString = encodeURIComponent(escape(desc));
//gs.print(encodedString);
var cleanedDesc = encodedString.replaceAll('%255Cr', "").replaceAll('%255Cn',"");
gs.print(cleanedDesc);
gr.setValue('short_description', cleanedDesc);
gr.update();
}
Result:
Hope this helps!
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"
Thank You
Juhi Poddar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2025 12:39 AM
Hello @venkram
I hope you are doing well.
Have you tried the solution provided by me?
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"
Thank You
Juhi Poddar