The CreatorCon Call for Content is officially open! Get started here.

When copying HTML field to journal field using Client script Tags are getting copied?Tags to remove?

VIKAS45
Tera Guru

When copying HTML field to Journal field using Client script Tags are getting copied?

 

How should we remove tags and copy only content from HTML field to Journal field using Client script?

4 REPLIES 4

Mohith Devatte
Tera Sage
Tera Sage

hello @VIKAS45 ,

Put your HTML code inside [code] tag and then try to populate it in journal field 

 Example:

[code]<a href="http://www.service-now.com">ServiceNow</a>[/code] 

 

Also before using code tag you need to check if this property is set to true in your instance in system properties table 

 

glide.ui.security.codetag.allow_script - should be true 

 

Hope this helps 

Mark my answer correct if this helps you 

Thanks

M Ismail
Tera Guru

Hi @VIKAS45 ,

When copying content from an HTML field to a Journal field  using a client script, you  want to remove any HTML tags and copy only the plain text content. Here's how you can achieve that:

Assuming you have an HTML field named html_field and a Journal field named journal_field, you can use this code as 


// Get the HTML field value
var htmlFieldValue = g_form.getValue('html_field');

// Remove HTML tags using a regular expression
var plainTextContent = htmlFieldValue.replace(/<[^>]*>/g, '');

// Set the plain text content to the Journal field
g_form.setValue('journal_field', plainTextContent);
In this script:

g_form.getValue('html_field') retrieves the value from the HTML field.
The regular expression /<[^>]*>/g matches HTML tags in the text.
.replace(/<[^>]*>/g, '') replaces all occurrences of HTML tags with an empty string, effectively removing them.
Finally, g_form.setValue('journal_field', plainTextContent) sets the plain text content to the Journal field.

 

If you find my response helpful in solving your query, please consider liking and marking my reply as the solution.

Thank you,
Ismail

Thank you Ismail How to remove &nbsp for space in HTML field

You can do this by using this piece of code 

var plainText = htmlContent.replace(/<[^>]+>/g, "").replace(/&nbsp;/g, " ");

 

Please like and Mark my answer correct if this helps you 

Thanks