Import Records in FileMaker

Is there any way to take a list of files and have FileMaker import in the file in the list without any user interaction? I can get FileMaker to do menu “Import Records” but can’t get it to select the file in the list. I have searched through many different posts but nothing that mentions it.

Thanks

While somebody comes with the correct answer (if you can really “import” data programatically), you can create a new record, then set contents of cell x to whatever. Eg:

set x to (list folder alias "path:to:folder:" without invisibles)

tell application "FileMaker Pro"
	tell database 1
		repeat with i in x
			set newRecord to (create new record)
			set cell "somename" of newRecord to i
		end repeat
	end tell
end tell

Thanks, but each file contains about 1000 tab delimited records. This would make it kind of cumbersome to set each field.

Hi,

I’ve used this to import a few thousand files containing a few thousand records each. First set up an import script in FMPro that imports a file named something like temp.txt, or temp.csv and make sure this file is imported from your source folder. To do this, maybe dupe one of your source files, rename it to “temp.txt” and set up your import script in FileMaker so it remembers the name of this file and the import order.

Then just run the following script. It will cycle thru each file in the source folder, rename the file to match your import script, perform the FMPro import script, then set the file name back to what it was (batch import).

Good Luck!

--this is the folder housing your files to be imported
property sourceFolder : "Mac HD:Desktop Folder:Project:Source:"
--this is the path to a temp file
property tempFileS : "Mac HD:Desktop Folder:Project:Source:temp.txt"

tell application "Finder"
	--get the name of  every file of the source folder
	set fileList to get the name of every file of folder sourceFolder
	
	repeat with thisFile in fileList --repeat on each file name
		--concat to get the file path
		set thisPath to sourceFolder & thisFile as string
		--change the name of the file to match the FP5 script
		set the name of file thisPath to "temp.txt"
		--have FMP do the import
		tell application "FileMaker Pro"
			--normally you wouldn't activate FMPro but in this case you would
			activate
			do script "massImport"
		end tell
		--set the name of the file back to what it was
		set the name of file tempFileS to (thisFile as string)
	end repeat
end tell

*As always, it’s a good idea to make a back-up of your database, and maybe even source files in case something goes horribly, horribly wrong. It won’t but I feel compelled to add that.

This is exactly the solution I came up with but found that renaming the file or deleting it caused a problem because FM was still using it. I tried renaming it then moving it which caused other problems. Since setting a delay wouldn’t work because every file import took different times.

I was hoping someone could tell me you could import “programically” but I just didn’t know it.

Thanks for your input.

What you talkin 'bout tmwillis?

This actually works for me as is but it should definitely work for you if the file is moved to another folder temporarily, then imported from there, and moved back.

Okay, how about this. Repeat with every source file:

  1. read
  2. write to the temp file
  3. import temp file

rinse
repeat

--this is the folder housing your files to be imported 
property sourceFolder : "Mac HD:Desktop Folder:Project:Source:"
--this is the path to a temp file 
property tempFileS : "Mac HD:Desktop Folder:Project:Temp:temp.txt"

--get the name of  every file of the source folder 
tell application "Finder" to set fileList to get the name of every file of folder sourceFolder

repeat with thisFile in fileList --repeat on each file name 
	--concat to get the file path 
	set thisPath to sourceFolder & thisFile as string
	--read the file
	set thisData to read thisPath
	--write it to the tempFile
	write thisData to tempFileS
	--have FMP do the import 
	tell application "FileMaker Pro"
		--normally you wouldn't activate FMPro but in this case you would 
		activate
		do script "massImport"
	end tell
end repeat