Importing a CSV File into FM Go
One thing most developers find out the hard way is that importing a CSV File into FileMaker Go is not natively supported. So, if you need to provide your users with a way to import data from a CSV file, you may think you are out of luck. I hadn’t tried that before, and found out that hard way that a work around is needed. One should check before saying “Yeah, FileMaker Go can do that”. Turns out it is true, but not as easy as one would think.
Anyway, I found a this thread on the FileMaker community from three years ago that was very helpful. It turns out there are two ways to work around this issue:
- Import the file into a webviewer and parse it out
- Use Insert from URL
Use a WebViewer for Import
The first option works as follows (hat tip to community user ‘roulf’):
- You can import a CSV file to FileMaker Go using the Web Viewer.
- Place the CSV document in FileMaker Go so you can see it in Files on iPad/iPhone.
- Example file: YourFile.csv
- In Layout, give the Web Viewer a Name such as WEBB – (Inspector: Position Tab).
- In Web Viewer, Web Address (Object name: WEBB) write: Get( DocumentsPath ) & “YourFile.csv”.
- Now you can see the CSV file like a spreadsheet in the Web Viewer.
- To import the information you have to write a script. Use GetLayoutObjectAttribute ( “WEBB” ; “Content” ) to place the data in a variable or a field
- When you use GetLayoutObjectAttribute on an iPad it grabs a lot of html with the data.
- You can study the data in the variable or field to figure how to scrape / parse the needed data.
The bolded part above shows one downside: a lot of extraneous data is in the import – data such as %20, %C1, and so on. This data needs to be cleaned up, which can be done via a custom function. But if you are importing a lot of data, that takes more time to clean. How do we avoid that problem? Use the Insert From URL script step.
Insert from URL
Insert from URL works better, and, as long as you do not click the Encode URL option, brings in clean, comma and CR delimited data.
Try it yourself using the attached Free FileMaker Example File.
Here’s a quick overview of the important part of the scripts:
Set Variable [$$Path; Value: Get(DocumentsPath) &”ContactImportTemplate.csv”]
Insert from URL [Select; With dialog: Off; $$Text; “file://” & Get(DocumentsPath) & $$Path; Do not automatically Encode URL]
The important part of the ‘Insert from URL’ script step is the path to the file: “file://” & $$Path is the secret to accessing the file using FileMaker Go.
There’s more – the import works on a Mac or on FileMaker Go, and the video below gives you a better look at what needs to be done for each:
So that’s how you go about importing a CSV file into FileMaker Go. And after successfully importing the CSV file to a variable (or a field), the next step is to parse the data into records. But that is a subject for possible future post!
“You do everything by the book, like everybody else, you get the same results as everybody else.”
― Jim Butcher