How can I get at the source code of an html field using a script?

Bonnie Cresswe2
Kilo Guru

I need to do some validation on an html field, checking the source html, but everything I have tried has not allowed me to get at the actual html. e.g if I have an html field where the source code is:

<p><strong>here we are testing</strong></p>

which displays in the field as:

here we are testing

anything I do in a business rule or client script returns just the text, i.e:

here we are testing

How can I get at the source html, i.e. including all of the html tags? 

I'm hoping I am just missing something really obvious...?

1 ACCEPTED SOLUTION

Bonnie Cresswe2
Kilo Guru

current.text.getHTMLValue() works, returns the html source code

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

So you want to get the value of html field with the tags as well

I tried this in background script and it gave me the complete html source code

Example script is for knowledge table

var gr = new GlideRecord('kb_knowledge');

gr.get('207de43187032100deddb882a2e3ec7a');

var html = gr.getValue('text');

gs.info(html);

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thanks Ankur, I found the answer last night, I'm now using current.text.getHTMLValue()

Your suggestion does also work so have marked as helpful

Bonnie Cresswe2
Kilo Guru

current.text.getHTMLValue() works, returns the html source code