Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to retrieve value from an HTML Type Field

Para5
Tera Guru

Hi All,
Is anyone knows how to retrieve value from an HTML Type Field. I have a field on form 'long_description'  And I want to print only the text  from it.

I tried this one   current.getValue('long_description');   but it print all the tag.

Thank you.

 

2 ACCEPTED SOLUTIONS

Updated script. added space between ""(double quote).

var regex =  /( |<([^>]+)>)/ig;
var content =current.getValue("long_description").replace(regex, " ");  

View solution in original post

@Para5 ,

 

Try the below code:

var regex =  /( |<([^>]+)>)/ig;
var content =current.getValue("long_description").replace(regex, " ");

I hope this help.

 

Please mark this helpful if this helps and Accept the solution if this solves your issue.

 

Regards,

Kamlesh

View solution in original post

7 REPLIES 7

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

Please check the below thread for the answer:-

 

https://www.servicenow.com/community/developer-forum/how-to-get-raw-text-from-html-field/m-p/2038036

 

Please mark my answer as correct based on Impact.

Hello,

 

Did you try the code I provided you:-

 

var text = current.long_description.getDisplayValue();

// Replace all <br /> tags with a CRLF

var regX1 = /<br\s\/>/ig;
var text2 = text.replace(regX1, String.fromCharCode(13));

// Replace all remainging HTML tags with ""

var regX2 = /(<([^>]+)>)/ig;
var finalText = text2.replace(regX2, "");

 

Please mark my answer as correct based on Impact

Yes I tried but its not working for me

kamlesh kjmar
Mega Sage

Hi @Para5 ,

 

Try the below code, it should work:

 

var regex =  /( |<([^>]+)>)/ig;
var content =current.getValue("long_description").replace(regex, "");

 

I hope this help.

 

Please mark this helpful if this helps and Accept the solution if this solves your issue.

 

Regards,

Kamlesh