- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2025 11:15 PM
Hi all,
there is a html field and the filed value we are showing on portal. When printing the new lines are replaced with
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2025 02:47 AM
You’re replacing <br/> with actual newline characters. This works in background scripts because it’s a backend context.
However, in the widget (browser/HTML context), the actual newline characters are not rendered visually in HTML. HTML ignores \n and \r\n unless inside elements like <textarea> or when explicitly styled.
1. if you already have <br/> in the value, then just use ng-bind-html in the widget template:
<div ng-bind-html="c.data.description"></div>
2. If you use ng-bind-html, and it doesn’t render the HTML tags properly, inject $sce to trust the content. And add this function on client side.
$scope.trustHtml = function(html) {
return $sce.trustAsHtml(html);
};
and then HTML will be:
<div ng-bind-html="trustHtml(c.data.description)"></div>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2025 11:36 PM
where are you writing that code?
share some more details
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-21-2025 01:06 AM
HI @Ankur Bawiskar have configured these lines in Server script on widget
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2025 01:39 AM
then try this
var msg = description.replace(/<br\s*\/?>/gi, '\n');
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-21-2025 02:39 AM