Filemaker

Resources

MacTech has a great introductory article on how to script Filemaker. The script below details a major caveat in doing so.

Duplicating Records

This duplicates all the found records in a document, and updates values. Running this multiple times in the same record set results in all of the records being updated, even the ones duplicated on the last run. The caveat to this script is that this only works on scripts that are stored and opened locally. For some strange reason, if a database is hosted on Filemaker server, record objects are returned as simple list with no reference to the actual record the data was grabbed from.

tell application "FileMaker Pro"
	set theDocument to document 1
	tell theDocument
		set lastRecord to count records
		repeat with r from 1 to lastRecord
			set theDuplicatedRecord to duplicate record r
			tell theDuplicatedRecord
				set cell "Foo" to ((get cell "Foo") & " DUPE")
				set cell "Bar" to ((get cell "Bar") & " DUPE")
			end tell -- duplicate record
		end repeat -- r as record
	end tell -- document
end tell