GlideElement: Get HTML text content

balu3
Kilo Guru

Hi All,

From the Knowledge table, I want to get the content from the field text. The content in the field is of type HTML.

I do not want the entire contents to be retrieved, I'm interested in only a part of it.

If I use the GlideElement getHTMLValue(maxChars) method, it returns even the HTML tags.

Like why is this happening. How can I retrieve only the text having 20 characters.

 

Here is my code

 

 

function getTextContents(query) {

  var textContents = [];
  var gr = new GlideRecord('kb_knowledge');
  gr.addEncodedQuery(query);
  gr.query();

  while (gr.next()) {
    textContents.push (gr.text.getHTMLValue(20));
  }

  return textContents;
}

 

Thanks in Advance

Balu

1 ACCEPTED SOLUTION

Harshad Wagh
Tera Guru

Hi Balu,

 

Please use following.

 

gr.text.getHTMLValue(20).replace(/<\/?[^>]+(>|$)/g, "");

 

Thanks

harshad

 

View solution in original post

5 REPLIES 5

Hi Balu,

Thank you for the update.

 

Appreciate if you mark the post as correct so it gets listed in solved so other can have s help form this if required.

 

Thanks again for sharing an update.

 

Best regards,

Harshad