Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Using stripHTML() but keep line breaks

KB15
Giga Guru

I'm definitely not great with regex. I'm trying to find a solution to covert html field to a multi-line field in a record producer to a record but all the regex I've looked at some posted don't seem to work right. I tried the stripHTML() function but that takes out line breaks which I will need to keep.

 

I've tried the below to get closer but it's still shows <p></p> and <a></a> in the field. Any options to remove these?

var desc = g_form.getValue(producer.description);
var cleanDesc = desc.replace(/\n/g, '<br>');
g_form.setValue('desciption', cleanDesc);
4 REPLIES 4

Manmohan K
Tera Sage

Hi @KB15 

 

Use below code , it will remove the p and a tags

 

 

var desc = g_form.getValue(producer.description);

cleanDesc= desc.replace(/<(?!br\s*\/?)[^>]+>/g, "");  

g_form.setValue('desciption', cleanDesc);

 

 

I'm not sure if this is by design in the HTML field or no but I still get the anchor and paragraph tags.

Shows up in the raw code view in the editor exactly as it does in the multi text field.

Manmohan K
Tera Sage

Hi @KB15

 

 

 

Try again, there was a typo in script. Description name was wrong in last line

 

var desc = g_form.getValue(producer.description);

cleanDesc= desc.replace(/<(?!br\s*\/?)[^>]+>/g, "");  

g_form.setValue('description', cleanDesc);

 

Also i tried in background script and it is working as expected

Sample input -

this is my <b>string</b> and it\'s pretty cool<br />isn\'t it?<br>Yep, it is. <strong>More HTML tags</strong>

Output received after running script - 

this is my string and it's pretty cool<br />isn't it?<br>Yep, it is. More HTML tags

 

 

Don't think that's the issue otherwise I would have had a blank description. It's something with the HTML editor and the record producer. Background script behaves differently.