How to remove double spaces for a field in the form?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-18-2023 05:58 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-18-2023 06:04 AM
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-18-2023 06:11 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-18-2023 06:13 AM
Hi @sruthig
Yes, trim() function will remove any extra space weather before or after a character or word.
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā05-18-2023 06:14 AM
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...