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

Joe S1
Kilo Sage

You could just run a background script and do a TRIM on the fields.

 

Code something like this:

var gr = new GlideRecord('table_name');
gr.query();

while (gr.next()){
     var clean1 = gr.field_name1.trim();
     var clean2 = gr.field_name2.trim();
     gr.field_name1 = clean1;
     gr.field_name2 = clean2;
     gr.update();
}

Hi 

Thanks for the response. Does the trim function removes the extra spaces before or after the field values? If I have extra spaces before as well as after how can I modify this back ground script?

Is the same code I can do with fix script/on demand scheduled job right?

Please suggest the best way?

Regards,

Sruthi

Hi @sruthig 

 

Yes, trim() function will remove any extra space weather before or after a character or word.

 

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

Hello,

 

Yes the trim() function trims leading and trailing spaces on a string value.

 

If the data is already existing in your system then just running a fix script one time should be enough. If new data is coming in with the spaces you need to do a trim wherever that data is coming in at? Import set, integration, etc...