Help

Re: Import csv via scripting with spaces and non-AlphaNumeric characters

847 0
cancel
Showing results for 
Search instead for 
Did you mean: 
ChrisM
4 - Data Explorer
4 - Data Explorer

Hi,

Sorry about the newbie question: via scripting, I´m trying to import a csv using .parsedContents however my csv has several spaces and non-AlphaNumeric characters in the headers so when I come to map the fields I don´t know how to specify them, for example line 4 in this snippet there´s a space between LAST and NAME:

1    let newRecords = fileRows.map(fileRow => ({
2        fields: {
3            'Email': fileRow.email
4            'Last Name': fileRow.last name,
5        }
6    }))

As I have several files to import several times a month I would not like to have to "cleanup" the csv in some other spreadsheet as it´d defeat the whole purpose of using airtable as I already have (an ugly) way of doing it all in excel.

Or is there a way to use the extension CSVImport via scripting using a predefined csv>table field pairing for each table?

Also, I´m wondering if it´s possible to run a script any other way apart from the side extensions panel.  Is there any way to have a custom button or hotkey to run a script?

Thanks in advance,
Chris

2 Replies 2
Juliana
Airtable Employee
Airtable Employee

Hi Chris! This might be a request that is best suited for an email to Support so that we could dig in a bit further, but as an initial guess, it might work to try fileRow["last name"] instead of fileRow.last name. More on this JS syntax here.

 

Regarding the follow-up questions:

  • “Or is there a way to use the extension CSVImport via scripting using a predefined csv>table field pairing for each table?”
    • No, I don’t believe that this is possible. The extension will “remember” field mappings between runs, but can’t be triggered by another scripting extension with mappings defined in code.
  • “Also, I’m wondering if it’s possible to run a script any other way apart from the side extensions panel. Is there any way to have a custom button or hotkey to run a script?”
    • The other two ways to run scripts are the Automation’s run a script action and button field. Cmd + Shift will open extensions but not run them. There’s not a way to (natively) set custom hotkeys, though perhaps a 3rd party browser extension or app would allow you to run “macros” of some sort.

Hope that this can help point you in the right direction!

ChrisM
4 - Data Explorer
4 - Data Explorer

Thanks Juliana, the JSSyntax you mentioned was what I was looking for. Thanks!