ANS-0134 · SAVED SEARCHES & FORMULAS

How to Display HTML Content in NetSuite Saved Searches for Web Stores

Effectively render dynamic HTML within NetSuite saved search results, addressing challenges with escaped characters and client-side rendering.

Short answer

To output HTML in NetSuite saved searches, utilize the 'Formula (HTML)' field type for direct rendering. For complex logic or client-side manipulation, store HTML in a freeform text field and use JavaScript with a secure unescaping method like DOMParser to correctly display the content.

Scenario

When displaying HTML content generated within NetSuite saved searches, particularly for use in web stores, users often encounter issues where the HTML is not rendered correctly. NetSuite's default behavior of escaping HTML characters can lead to raw HTML tags being displayed as plain text rather than formatted content, requiring specific solutions for proper rendering.

Solution

The most straightforward method for rendering HTML directly within NetSuite saved searches is to leverage the 'Formula (HTML)' field type. This dedicated field type is designed to interpret and display HTML content without requiring client-side unescaping, making it the recommended approach for direct HTML output. If the logic for generating the HTML is concise enough to fit within a saved search formula, this is the easiest solution.For scenarios where the HTML generation logic is too extensive for a saved search formula, or when dynamic client-side manipulation is required, a scripting approach can be employed. This involves storing the generated HTML within a standard freeform text field in NetSuite. Subsequently, client-side JavaScript, often utilizing libraries like jQuery, can retrieve this non-rendered HTML and process it for proper display.A common challenge with this scripting method is that NetSuite outputs HTML with characters escaped (e.g., < for <). Client-side scripts must unescape these strings before rendering. While the unescape() method in JavaScript is deprecated and will not correctly handle HTML entities, a custom function can be used. The following htmlDecode function provides a way to unescape HTML entities, though for enhanced security against Cross-Site Scripting (XSS) vulnerabilities, modern JavaScript offers more robust approaches such as using DOMParser.

javascriptfunction htmlDecode(input){  var e = document.createElement('div');  e.innerHTML = input;  return e.childNodes.length == 0 ? "" : e.childNodes[0].nodeValue;}

An example of jQuery code used to locate and process such links within a saved search output is provided below:

javascript//replace link string in saved search by actual link$j('td.listtexthl:contains("<a href")').each(function(index,element){     var linkObject = $j(this).html().replace(/</gi,"<").replace(/>/gi,">");     $j(this).html(htmlDecode(linkObject));});

Expert NetSuite Support

Need help with this NetSuite issue?

Saved Searches & Formulas consulting and configuration support

Talk to a consultant