Getting values from FileMaker to Xcode Project

I am updating a Xcode 3 AppleScript project written some time ago to a Xcode 5 Cocoa-Applescript project. All seemed well up to the point where I am trying to return at value from FileMaker back into the project.

From AppleScipt editor this script dutifully returns the auto-entered serial number in the field RecordID:

set theTargetDatabase to "Email Archive"

tell application "FileMaker Pro" to tell database theTargetDatabase
	set theRecord to create new record at table "MailMessages"
	set theRecordID to cell "RecordID" of theRecord
end tell

The same script commands in Xcode give me a new FileMaker record but there is a problem getting the RecordID. Alternative forms I’ve tried:
set theRecordID to cell “RecordID” of theRecord → FileMaker Pro got an error: Object not found. (error -1728)
set theRecordID to cell “RecordID” of record theRecord → FileMaker Pro got an error: Object or property is the wrong type. (error -10001)
set theRecordID to (cell “RecordID” of theRecord) as integer → Can’t make «class ccel» “RecordID” of «class crow» id 3.2818E+4 of window “Email Archive” of application “FileMaker Pro” into type integer. (error -1700)

The last form makes me think I’m addressing the right information but I’m lost on how to get it as a number in the theRecordID variable.

I would be grateful to anyone who can point out the error of my ways and get me back on track.

Model: iMac
AppleScript: Xcode 5
Browser: FileMaker Pro 13
Operating System: Mac OS X (10.8.5)

Hello,

Did you try


set theRecordID to (get cell "RecordID" of theRecord)

If by chance it would solve the problem?

Hi Joseph

set theRecordID to (get cell “RecordID” of theRecord) gives me : Object not found
and
set theRecordID to (get cell “RecordID” of record theRecord) gives me : Object or property is the wrong type.

Same as before sadly, thank you for the suggestion anyway.

Hi, Don_R

Sorry for you.
Excuse me for the roughness of my question:
I acknowledge that too much times Applescript is quite esoteric,
but did you look at File Maker’s Applescript dictionary in the a possible syntax for getting its value?

Maybe have a look at this page:
http://www.mactech.com/articles/mactech/Vol.22/22.04/ScriptingFileMakerPro/index.html

HTH

Hi Joseph

I think the problem lies with something that Xcode is doing. Those few lines of script are fine running from AppleScript Editor and were part of my earlier AppleScript Xcode project.

My suspicion is that there is some difference between the ways AppleScript and Cocoa’s AppleScriptObjC talk to records in FileMaker.

My head scratching (and frustration) continues but thanks again for your thoughts.

That suggests you are trying to coerce it to an an integer, which is not in the code you posted. Could it be that the error isn’t happening where you think it is?

Hi Shane

Thanks for joining in on this.

My first try was

which gives

a later attempt was

which gives

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.

Any pointers would be greatly appreciated.

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”?

“Object not found” in both cases.

What happens if you try to get the cellValue of a cell that already exists? Say, of record 1?

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.

(Signing off 3:06 UK time).

After breakfast: are you editing the script within Xcode or a script editor?

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?

Shane - script editing all within Xcode.
Joseph - Nice idea. I don’t know how to implement that but will have a look.

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.

Script compiles with no issues in Script Editor.

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.

So what code was trying to do that coercion?

set theRecordID to cell “RecordID” of theRecord as integer

when I try it without coercion I get a FileMaker error: “Object not found.”