Covert the String value to HTML value

Black Coder
Tera Guru

Hi How to convert the String value to HTML value. We are in a need of bringing the description to Service portal widget. Even though the string type of description field has got line break, when the time of it is showed on service portal all the text are displayed in same line without line break.

How could it be sorted out

5 REPLIES 5

Ct111
Tera Sage

For string to html sample example:

var s = '';

var htmlObject = document.createElement('div'); htmlObject.innerHTML = s; htmlObject.getElementById("myDiv").style.marginTop = something 

 

Try something like this .

Note : Dom is not best practice but if it is unavoidable then you can use this.

 

Mark my Answer as CORRECT and HELPFUL if it helps

 

 

 

 

GM5
Giga Guru

I need to do the same, but before warning us about DOM manipulation, the intent is not to do that, we need to grab the contents of the Description field, and then convert into HTML for later being used on a prototype translation web service that supports text with HTML strings.

 

For example I have on my Description field something like:

 

* Services are dependent on the organization tied to the incident (typically affected user org)
* Categories are dependent on the service selected.
* Subcategory is dependent on the category selected

Then we want to parse or convert to HTML so we get something like:


<li>Services are dependent on the organization tied to the incident (typically affected user org)</li>
<li>Categories are dependent on the service selected.</li>
<li>Subcategory is dependent on the category selected.</li>

Martin Grosskop
Tera Guru

Have you looked at the functions available in GlideStringUtil?

eg getHTMLValue

https://developer.servicenow.com/dev.do#!/reference/api/rome/server/no-namespace/GlideStringUtilScopedAPI#GSUS-getHTMLValue_S

 

How to convert string field values to html field value in ui page