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.

While Copying HTML field to Journal field using Client Script and removing HTML Tags &nbsp is seen?

VIKAS45
Tera Guru

While Copying HTML field to Journal field using Client Script and removing HTML Tags &nbsp is still  seen?

// 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);

 

How to remove &nbsp which is still seen after copying?

2 ACCEPTED SOLUTIONS

Jaspal Singh
Mega Patron
Mega Patron

Can you try below.

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

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

//remove &nbsp
var plainTextContentis=plainTextContent.replace(/&nbsp/g','');

// Set the plain text content to the Journal field
g_form.setValue('journal_field', plainTextContentis);

View solution in original post

Thank you Jaspal,

 

After removing HTML Tags and &nbsp  we recieved ; semicolon which we replaced and then got the Correct Solution with below script.

 

var itgj = g_form.getValue('html_field');
 
// Remove HTML tags using a regular expression
var plainTextContent = itgj.replace(/<[^>]*>/g, '');
 
//remove &nbsp
var plainTextContentis=plainTextContent.replace(/&nbsp/g,'');
 
var plainTextContent1 = plainTextContentis.replace(/;/g, '');
 
// Set the plain text content to the Journal field
g_form.setValue('journal_field', plainTextContent1);

View solution in original post

5 REPLIES 5

Jaspal Singh
Mega Patron
Mega Patron

Can you try below.

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

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

//remove &nbsp
var plainTextContentis=plainTextContent.replace(/&nbsp/g','');

// Set the plain text content to the Journal field
g_form.setValue('journal_field', plainTextContentis);

Thank you Jaspal,

 

After removing HTML Tags and &nbsp  we recieved ; semicolon which we replaced and then got the Correct Solution with below script.

 

var itgj = g_form.getValue('html_field');
 
// Remove HTML tags using a regular expression
var plainTextContent = itgj.replace(/<[^>]*>/g, '');
 
//remove &nbsp
var plainTextContentis=plainTextContent.replace(/&nbsp/g,'');
 
var plainTextContent1 = plainTextContentis.replace(/;/g, '');
 
// Set the plain text content to the Journal field
g_form.setValue('journal_field', plainTextContent1);

Great to know the approach worked. Seems, the suggested answer was not marked correct instead.

Done Jaspal