Script works in Script Editor, not in FileMaker Pro

Hi all

I’ve been banging my head against the wall for hours with what seems like an Applescript gremlin.

What it boils down to is that the following piece of code:

tell application “FileMaker Pro”
set data of cell “Text 1” of current record to “Yes”
set data of cell “Text 2” of current record to “No”
set data of cell “Text 3” of current record to"No"
end tell

works fine when executed from within Script Editor. However, when run from within a FileMaker script, using the “Perform Applescript” step, the first of the three lines executes correctly, but the second one then generates the error:

“FileMaker Pro got an error: Set Data failed. Invalid Data was supplied. (Error -17005).”

I stress however that the first line is executing because the field “Text 1” is indeed filled with the word “Yes” and, if I remove the second and third lines, I do not get the error at all. Therefore it cannot be true that invalid data is being supplied, since it works fine for the Text 1 field.

Eeek! HELP!!!

Wanderer

Well, it probably is NOT an AppleScript gremlin per se, but more likely a FileMaker gremlin. I ran that code here (from a Perform AppleScript step) on Mac OS X 10.3.2, running FileMaker Pro 6.0.4, and it worked without a problem. A few things I’d recommend trying: drop the tell and end tell lines - you don’t need FileMaker to tell itself to do something, FileMaker is the one running the script. That may help although, as I said, it works here as you wrote it without a hitch. You could also try this syntax:


set cellValue of cell "Text 1" of current record to "Yes" 

That is supposedly a more explicitly accurate model of what you want to do - change the cellValue of a cell of a record.

All that said, I’ve seen a bunch of FileMaker-AppleScript interaction problems that I believe are related to what seems to be a have-though-out implementation of FileMaker’s AppleScript support, and have had code that ran fine one time fail another, without the hardware, software, or parameters changing between runs. FileMaker also can have problems allowing an Apple Event to run while it is doing something else. People used to work around this by having an external “stay-open” applet that FileMaker could send a “don’t wait for answer” event to. The applet would, in turn, tell FileMaker to do something. This was quite a difficult work-around to set up, and FileMaker normally does not need it anymore, but I have seen behavior that implies the easier, more sensible-seeming method sometimes fails.

Good luck!

Krioni,

Thanks for all your suggestions, but I’m afraid I’ve tried them and drawn a blank on them all.

It seems that, fundamentally, FileMaker can only execute one “Set” command per script without generating an error. This being the case, I’ve thought of a workaround, but I still need some help with that.

I simplified my code in my previous post to make my question easier to ask. Actually, I have three variables to go into FileMaker fields, rather than the “Yes”, “No” and “No” as per my post. If I can put all three variables into the same FileMaker field, separated by commas, I can then use a calculation field in FileMaker to split them apart again. That way, I only need to use one “Set” command in my Applescript, which should mean that I avoid any errors.

So, effectively what I need is the syntax to do the following:


If a certain condition is met then Set Var1 to “Yes” (I can do this bit)
If a certain condition is met then Set Var2 to “No” (I can do this bit)
If a certain condition is met then Set Var3 to “No” (I can do this bit)
Set data of cell “MyField” of current record to “Yes,No,No”

The only bit I don’t know how to do is the concatenation of the three variables with the commas to make the string I need to stick into the FileMaker field.

Sorry if this is a really basic question at the end of the day, I don’t dip into Applescript very often!

Cheers

Wanderer

All of the code presented so far, including the following, works on my setup (FMP 6, OS X 10.2.8). Does this work for you?

tell application "FileMaker Pro"
	tell current record
		set {cell "Text 1", cell "Text 2", cell "Text 3"} to ¬
			{"Yes", "No", "No"}
	end tell
end tell

If not, does it help to add a delay between the commands?

tell application "FileMaker Pro"
	tell current record
		set data of cell "Text 1" to "Yes"
		delay 1
		set data of cell "Text 2" to "No"
		delay 1
		set data of cell "Text 3" to "No"
	end tell
end tell

Your code to build the list works here (Set data of cell “MyField” of current record to “Yes,No,No” ).

– Rob

Rob, thanks for your constructive suggestions, I can see your thinking behind them all and I got really excited thinking one of them would do the trick.

Alas, not so!

The same error is generates regardless of which of the structures of code I use. Even if I increase the delay to 5 or 10, the first Set Data executes fine, then the first delay happens, and then as soon as the second Set Data is executed, the error generates.

I am in OS9.2 with FMv6. From what you guys say, this won’t be a problem under OSX so I guess I shouldn’t worry too much. Another guy here has an OSX maching so I’ll try running the code under that and see what happens.

Cheers

Wanderer

How about :-
tell application “Filemaker Pro”
set answer1 to “Yes”
set answer2 to “No”
set cell “Text 1” of current record to answer1
set cell “Text 2” of current record to answer2
set cell “Text 3” of current record to answer2

end tell

Nice try drc, but no cigar there either.

For some reason, on my operating system, I can only execute one set field step in each script. Grrrr!

Wanderer

Does this work?

In FMP, I went to ScriptMaker and created a new script named “Test”. From here, for the action of the script, I selected “perform AppleScript” from the “Misc.” action section. Then I clicked the “Specify…” button and entered this into the script text window:

set the_cell_names to {"Text 1", "Text 2", "Text 3"}
set the_cell_values to {"Yes", "No", "No"}
tell application "FileMaker Pro"
    tell current record
        repeat with i from 1 to (count of the_cell_names)
            set cellValue of cell (item i of the_cell_names) to (item i of the_cell_values)
        end repeat
    end tell
end tell

Then I clicked “OK” to everything and closed the ScriptMaker dialog. Then, in layout mode, I made a new button in my DB and set the action to “perform script” and selected the “Test” script I just created. Switching back to browse mode and trying the button (with the proper fields defined, of course), worked perfectly in FMP 5.5 so I assume it will work in FMP 6. Of course, once the script is created, you can just run it from the scripts menu without attaching it to a button. Here’s a link to the sample DB I created:

http://homepage.mac.com/jonn8/as/dist/run_script.hqx

Hope this helps,
Jon

When you tell FileMaker to set a cell value, you usually need to specify the document (current found set) or database as the parent of the record whose cell you are trying to set. You also do not need to use “cellValue” or “data” to set the field value.

I’ve never used “field”, instead I always use “cell” as the object type.

Try this:


tell application "FileMaker Pro"
    tell front database
        set cell "Text 1" of current record to "Yes"
        set cell "Text 2" of current record to "No"
        set cell "Text 3" of current record to "No"
    end tell
end tell

If you are getting an error saying the wrong data type was supplied, verify that the field type is not set to somthing other than “Text” in “Define Fields”. This error usually occurs when the data type for the field is set to “Number”, “Date” or a container of a type other than “Text”.

Scott Lewis
MacScripter Staff