Skip to main content

I will not go into full detail because it is exhausting, but I have run into a situation where data written into my base occasionally has a trailing space character, which caused confusion and havoc between airtable and softr over the past 4+ weeks.

The extra [space] character is really just typo. But to the naked eye, it cannot even be seen. How can I prevent any trailing [space] characters being written in the future?? Is there a native trim function?

Hi,

you can use this script do untrim text fields in any table.
Regarding ‘how to prevent’ - it depends if how the data added if your base
 

const untrim=async table=>{
let fields=table.fields.filter(f=>f.type.includes('Text')).map(f=>f.name)
const query=await table.selectRecordsAsync({fields});
const trimmed=rec=>fields.map(f=>[f,rec.getCellValue(f)?.trim()])
const change=rec=>Object.fromEntries(trimmed(rec).filter(([f,v])=> v!=rec.getCellValue(f)))
const upd=query.records.map(rec=>({id:rec.id,fields:change(rec)})). filter(u=>Object.keys(u.fields).length)
console.log(`Fields: ${fields.join(', ')}.\nTo update: ${upd.length} records`)
console.log(upd.slice(0,50))
while (upd.length) await table.updateRecordsAsync(upd.splice(0,50))}

let table = await input.tableAsync("Select the table to trim text fields")
//to process all base replace line above with: for(let table of base.tables)
await untrim(table)

 


@RedwolfSports 

You can create a formula field using the TRIM() function:

TRIM({Your Text Field})

If you need to get the results of that formula back into the original text field, you could create an automation to overwrite the original text field with the results of that formula.

Hope this helps!

If you have a budget and you’d like to hire the best Airtable consultant to help you with this or anything else that is Airtable-related, please feel free to contact me through my website: Airtable consultant — ScottWorld