How to get the display value of an Translate HTML field and display it at a String field ?

Eddie_Cheong
Kilo Contributor

How to get the display value of an Translate HTML field and display it at a String field ? I was trying to get the text field content from an knowledge article and set the value into a string description field using a record producer, but the result show the HTML source code instead. I tried to get the Display value of the article Text field but this too show me the HTML source code.

current.description = producer.u_article_number.text;

or

var txt = producer.u_article_number.text.getDisplayValue();

current.description = txt;

** u_article_number is a variable in the record producer asking user to enter/select an article number. ***

both return me with the same result.

1 REPLY 1

Duodecimal
Mega Guru

I had to create a custom function to do this -- if there's a standard way to do it I'd like to know.



We have a script include named "uLibrary" that has a lot of our general methods. This one tries to preserve the general shape of the HTML (not including tables), and also makes an attempt to remove some of the extra paragraph spacing HTML fields tend to insert (I believe this is fixed in Fuji 10 or 11, can't remember which):



uLibrary.html2text = function (html) {


    if (typeof html == "undefined") return "";


    if (typeof html != "string") html = html.toString();


    if (!html) return "";


    var text = html.replace(/<\/?p>/gi, "\n")


    .replace(/<\/?br\s*\/?>/gi, "\n")


    .replace(/<li>/gi, " * ")


    .replace(/(<(?:.|\n)*?>)/gm, "")


    .replace(/\&nbsp/g, " ")


    .replace(/(\n\s*)+/g, "\n")


    .trim();


    return text;


}



Real developers would probably have try / catch and better error checking in there, but the .replace methods should be good since I think I stole some of them from stackoverflow somewhere - particularly line 8.



Note: line 9 should not have the backslash before the ampersand -- I had to escape it so it wouldn't be just "/ /g" in the first parameter.