Saturday, December 16, 2017

#1 2015-09-17 11:55:07 am

Don_R
Member
From:: UK
Registered: 2015-09-17
Posts: 13

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:

Applescript:

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)


Filed under: value, FileMaker, xcode, cell

Offline

 

#2 2015-09-17 12:59:03 pm

Joseph25b
Member
Registered: 2015-08-31
Posts: 31

Re: Getting values from FileMaker to Xcode Project

Hello,

set theRecordID to cell "RecordID" of theRecord --> FileMaker Pro got an error: Object not found. (error -1728)


Did you try

Applescript:


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

If by chance it would solve the problem?


Joseph from France
MacPro 10.7.5 - XCode 4.6.3

Offline

 

#3 2015-09-17 01:45:19 pm

Don_R
Member
From:: UK
Registered: 2015-09-17
Posts: 13

Re: Getting values from FileMaker to Xcode Project

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.

Offline

 

#4 2015-09-17 02:37:04 pm

Joseph25b
Member
Registered: 2015-08-31
Posts: 31

Re: Getting values from FileMaker to Xcode Project

Hi, Don_R

Don_R wrote:

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.


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 <cell properties> a possible syntax for getting its value?

Maybe have a look at this page:
<http://www.mactech.com/articles/mactech … index.html>

As you can see by the code above, it is not actually necessary to reference a parameter of a cell in order to retrieve the cell's value. Simply referring to the cell itself will result in the value of that cell. Other methods of requesting a cell's value include, using the get data command, as well as accessing the cellValue property of the cell class.


HTH


Joseph from France
MacPro 10.7.5 - XCode 4.6.3

Offline

 

#5 2015-09-17 04:53:14 pm

Don_R
Member
From:: UK
Registered: 2015-09-17
Posts: 13

Re: Getting values from FileMaker to Xcode Project

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.

Offline

 

#6 2015-09-17 06:59:07 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5200

Re: Getting values from FileMaker to Xcode Project

Don_R wrote:

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)


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?


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#7 2015-09-17 08:06:08 pm

Don_R
Member
From:: UK
Registered: 2015-09-17
Posts: 13

Re: Getting values from FileMaker to Xcode Project

Hi Shane

Thanks for joining in on this.

My first try was

set theRecordID to cell "RecordID" of theRecord


which gives

Object not found.


a later attempt was

set theRecordID to cell "RecordID" of theRecord as integer


which 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.


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:

Applescript:

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.

Offline

 

#8 2015-09-17 08:23:57 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5200

Re: Getting values from FileMaker to Xcode Project

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


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#9 2015-09-17 08:44:43 pm

Don_R
Member
From:: UK
Registered: 2015-09-17
Posts: 13

Re: Getting values from FileMaker to Xcode Project

"Object not found" in both cases.

Offline

 

#10 2015-09-17 08:49:20 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5200

Re: Getting values from FileMaker to Xcode Project

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


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#11 2015-09-17 09:07:19 pm

Don_R
Member
From:: UK
Registered: 2015-09-17
Posts: 13

Re: Getting values from FileMaker to Xcode Project

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).

Offline

 

#12 2015-09-17 09:11:05 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5200

Re: Getting values from FileMaker to Xcode Project

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


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#13 2015-09-18 03:45:15 am

Joseph25b
Member
Registered: 2015-08-31
Posts: 31

Re: Getting values from FileMaker to Xcode Project

Don_R wrote:

Running this I do get a new record in FileMaker and a log entry in Xcode but …


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?


Joseph from France
MacPro 10.7.5 - XCode 4.6.3

Offline

 

#14 2015-09-18 04:46:50 am

Don_R
Member
From:: UK
Registered: 2015-09-17
Posts: 13

Re: Getting values from FileMaker to Xcode Project

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

Offline

 

#15 2015-09-18 04:49:20 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5200

Re: Getting values from FileMaker to Xcode Project

Don_R wrote:

Shane - script editing all within Xcode.


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.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#16 2015-09-18 05:29:27 am

Don_R
Member
From:: UK
Registered: 2015-09-17
Posts: 13

Re: Getting values from FileMaker to Xcode Project

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?

Offline

 

#17 2015-09-18 07:03:52 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5200

Re: Getting values from FileMaker to Xcode Project

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.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#18 2015-09-18 07:20:35 am

Don_R
Member
From:: UK
Registered: 2015-09-17
Posts: 13

Re: Getting values from FileMaker to Xcode Project

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.

Offline

 

#19 2015-09-18 07:27:20 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5200

Re: Getting values from FileMaker to Xcode Project

Don_R wrote:

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.


So what code was trying to do that coercion?


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#20 2015-09-18 07:41:09 am

Don_R
Member
From:: UK
Registered: 2015-09-17
Posts: 13

Re: Getting values from FileMaker to Xcode Project

set theRecordID to cell "RecordID" of theRecord as integer

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

Offline

 

#21 2015-09-18 07:42:39 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5200

Re: Getting values from FileMaker to Xcode Project

I think I'm stumped at this point...


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#22 2015-09-18 07:50:00 am

Don_R
Member
From:: UK
Registered: 2015-09-17
Posts: 13

Re: Getting values from FileMaker to Xcode Project

I think I'm stumped at this point...


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!!

Offline

 

#23 2015-09-18 09:35:25 am

Joseph25b
Member
Registered: 2015-08-31
Posts: 31

Re: Getting values from FileMaker to Xcode Project

Don_R wrote:

I'll try to give Joseph's suggestion a go, …!


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

Applescript:


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 {":"}

My two cents ;-)


Joseph from France
MacPro 10.7.5 - XCode 4.6.3

Offline

 

#24 2015-09-18 09:52:35 am

Don_R
Member
From:: UK
Registered: 2015-09-17
Posts: 13

Re: Getting values from FileMaker to Xcode Project

Xcode is very touchy about syntax while AppleScript editor passes trough


Agreed Xcode can be very touchy. Thank you Joseph, I'll let you know how I get on.

Offline

 

#25 2015-09-19 09:20:12 am

mouramartins
Member
From:: Algarve
Registered: 2010-11-21
Posts: 156

Re: Getting values from FileMaker to Xcode Project

Try "cellValue of cell …"

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)