How to keep formatting of description as it is when copying into HTML type Description field.

Sonu Parab
Mega Sage
Mega Sage

Hi All,

 

We have Description field o the incident form and its type is String.
We have another field HTML Description and its type is HTML, where we are copying the Description into HTML Description field using one UI ACTION.

The issue is when we copy the  description into the HTML description it looses its formatting.

So is there any way to keep formatting  as it is in the HTML Description field.

Could you please refer below snippet.

SonuParab_1-1693141785826.png

SonuParab_2-1693141932552.png

 

Thanks you.

 

 

2 REPLIES 2

Samaksh Wani
Giga Sage
Giga Sage

Hello @Sonu Parab 

 

Use this :-

 

 

string.replace(/\n/g, '<br></br>');

 

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.

 

Regards,

Samaksh

 

Hello @Sonu Parab,

I would just like to enhance @Samaksh Wani answer with carriage returns as well. Because sometimes there are not only new lines, but carriage returns as well.

 

var description = current.description; // get the String value from the Description field
var htmlDescription = description.replace(/(?:\r\n|\r|\n)/g, '<br>'); // replace new lines carraiage return with <br> tags
current.html_description = htmlDescription; // set the HTML value to the HTML Description field

 

Kind Regards,

Swarnadeep Nandy