Run Filemaker Script

Hi,
I’m trying to run a filemker script from Applescript with “do script FileMaker script”, my filemaker script has a difrent data for each record, and olnly run for last one, this is the code

tell application "FileMaker Developer"
	tell database MyDatabase
		set NuRecords to count record of database MyDatabase
		repeat with i from 1 to NuRecords
			do script FileMaker script "MyFilemakerScript"
		end repeat
	end tell
end tell

Does anyone know where is the error or what other way for run filemaker scripts for each record.

Thank you
M!

Unless the Filemaker script that you call has some smarts, I wouldn’t expect anything different.

If you decode your script, you’ll see it says:

      repeat with i from 1 to NuRecords 
         do script FileMaker script "MyFilemakerScript" 
      end repeat 

Now, if there’s 100 records in the database, you could rewrite it as:

      repeat 100 times 
         do script FileMaker script "MyFilemakerScript" 
      end repeat 

Nowhere in there does it tell Filemaker anything about iterating through the records in the database.

Assuming the Filemaker script affects the current record, try something like:

      repeat with i from 1 to NuRecords 
         go to record i of database MyDatabase
         do script FileMaker script "MyFilemakerScript" 
      end repeat 

In this example, you iterate through each record before calling the Filemaker script.

You could also change the Filemaker script to iterate through the records, changing the AppleScript to just call the Filemaker script once rather than once per record. Not sure which would be faster.

Calling the Filemaker script once will be much faster than calling it many times. It is always much faster to do as much with Filemaker scripting as possible. Every iteration of the Applescript loop will be an apple event and they are slow.

Drossi is right. The script will be much faster if you use FileMaker’s scripting capabilities as much as possible. Judging from your code you could do all of this with ScriptMaker and not AppleScript. If you are launching this script from outside FileMaker you could use AppleScript to simply send the command to perform the script.