How to remove double spaces for a field in the form?

sruthig
Tera Expert

Hi Team,

I have 2 string field in my form. Fund Name and Fund Number. How can I clean up the the  existing this 2 field with leading double spaces?

Please suggest the way and a example code

Regards,

Sruthi

19 REPLIES 19

@sruthig 

no need of those 2 variables

var gr = new GlideRecord('table_name'); 
gr.query(); 
while (gr.next()){ 
	gr.field_name1 = gr.field_name1.trim();
	gr.field_name2 = gr.field_name2.trim();
	gr.update();
}
Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

@sruthig 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

 

I tried the below fix script but it is not removing the extra spaces after Run Fix Script. Please suggest

sruthig_0-1684484591132.png

I have added spaces before Testing as below. But not removing the extra spaces after Run Fix Script

sruthig_1-1684484931711.png

 

@sruthig 

try to use toString() before using trim() method

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

Thanks for the response. It's working when I add string().

Can you please help me how to remove extra space in between 2 strings
Example - Testing Test (If in between Testing and Test 2 spaces then how to remove the one space)

Please suggest.

Regards,

Sruthi