I’ve taken to heart the rocommendation in your book to use the log command extensively for debugging. The code as it currently appears in Xcode:
tell application "FileMaker Pro" to tell database theTargetDatabase
tell table "MailMessages"
set theRecord to create new record
tell current application to log "record created" --> works to here
set theRecordID to cell "RecordID" of theRecord
tell current application to log "RecordID obtained"
end tell
end tell
Running this I do get a new record in FileMaker and a log entry in Xcode but then it stalls with an error, “Object not found” in this case, and no further log entries. I agree that the problem might not necessarily be with the “set theRecordID.” command itself but I’m stumped as to why the script stops there.
I haven’t done anything with FileMaker for a long time. What happens if you ask for “cellValue of cell “RecordID” of theRecord” or “formula of cell “RecordID” of theRecord”?
Pointing to an existing record I get “Object or property is the wrong type” when I reference either a numeric or text field in FileMaker.
As this is the first instance of theRecordID it has not got a property statement at the start of the script, but even when I add “property theRecordID : 0” or “property theRecordID : “”” the error message remains the same.
I’m thinking about an ugly way but that worked for me in similar case (not with FM though):
Since Xcode can retrieve the full record as log, put it in a variable and coerce it as list,
then go through the var to pick out the right item (property) you need?
Try selecting the file and choosing File → Open in External Editor. That should open it in Script Editor. Compile it there, and see if you spot anything odd happening with terminology.
Although I do have breaking news. I have copied the project to another machine that has OS X 10.8.5, Xcode 5, FMP11. The only difference being FMP13 on first machine (which also has FMP9).
Application runs correctly on 2nd machine with Debug and Release builds but if I run the built product back on the first machine it appears to stop at the same point. This has really confused me.
I’ve run all OS updates and done new installs of Xcode and FMP. Each time “set theRecordID to cell “RecordID” of theRecord” works fine from AppleScript Editor but not from Xcode or the app…
I hope I have described things clearly. Might there be something missing from the first machine?
Could both versions of FM be running? I’ve had the same thing happen with other apps – running an app that targets them from Xcode results in a different version launching.
If I lauch FMP in advance and open the target database then Xcode doesn’t try to open the other.
The version of the commad that gives “Can’t make «class ccel» “RecordID” of «class crow» id 3.2818E+4 of window “Email Archive” of application “FileMaker Pro” into type integer.” makes me believe that Xcode is addressing the right field in the right database.
I’ve uninstalled FMP13 as the earlier version does communicate properly with the older version of the app.
Ha! Join the club. Thank you so much for your input though.
I’ll try to give Joseph’s suggestion a go, failing that I’m going to use an old machine to make my script updates to the old app in Xcode 3 using pure AppleScript. Yuk!!
Before you dive in it, may I suggest you try thoroughly parenthesis usage in your code?
a few tries with different position, like this for example
set theRecordID to (cell "RecordID" of theRecord) as integer
Xcode is very touchy about syntax while AppleScript editor passes trough
an example I discovered after a good headache
set text item delimiters to “:” runs in AS editor
and likely fails in Xcode because the original syntax is
set AppleScript’s text item delimiters to {“:”}