HTML Tags Description field

VasukiS
Tera Guru

HI Team,

 

In the HR Module, we are using the rich_description field. Any text entered into the rich_description field. It is also copied into the description field as per the out-of-the-box behavior.

However, while copying the data, it includes HTML tags.

Is this out-of-the-box behavior if we choose to use the rich_description field? 

 

1 ACCEPTED SOLUTION

folusho
Tera Guru

@VasukiS 

If you want to preserve only the plain text in description, you should strip the HTML tags when copying from rich_description.

 

Use BR....

function stripHTML(html) {
    var tmp = new GlideElement();
    tmp.setDisplayValue(html);
    return tmp.getDisplayValue().replace(/<[^>]*>/g, '');
}

// In Business Rule:
current.description = stripHTML(current.rich_description);

 

  or Flow (script step)

var plainText = current.rich_description.replace(/<[^>]*>/g, '');
current.description = plainText;

 

View solution in original post

3 REPLIES 3

Gaurav Rathaur
Kilo Guru

Hi @VasukiS ,

 

The inclusion of HTML tags when copying data from the rich_description field to the description field is indeed the out-of-the-box behavior in ServiceNow. This happens because the rich_description field uses a rich text editor, which stores content as HTML to preserve formatting (like bold, italics, lists, links, etc.).

If the requirement is to strip the HTML tags before copying the content to the description field, you can use the gs.stripHTML() function in a business rule or a script include to handle this.

 

If my response was helpful, please mark it as the correct answer and close the thread. This will help others who come across the same issue.

Thanks!
Gaurav Rathaur

folusho
Tera Guru

@VasukiS 

If you want to preserve only the plain text in description, you should strip the HTML tags when copying from rich_description.

 

Use BR....

function stripHTML(html) {
    var tmp = new GlideElement();
    tmp.setDisplayValue(html);
    return tmp.getDisplayValue().replace(/<[^>]*>/g, '');
}

// In Business Rule:
current.description = stripHTML(current.rich_description);

 

  or Flow (script step)

var plainText = current.rich_description.replace(/<[^>]*>/g, '');
current.description = plainText;

 

@VasukiS 

Thanks for marking my solution as helpful.

Please can you mark as solution given so as to help others in the community.

 

Regards.