Jump to content
Sign in to follow this  
DataChris

Get(LayoutTableName)

Recommended Posts

DataChris

Is there a way for FileMaker to accept a field name in a script that's defined with a syntax similar to.... "Get(LayoutTableName)::FieldName"

 

It seems the only way FileMaker will accept a field name in a script calculation is if the actual name of the field is typed out. For example "Contacts::Name"

 

I would like to use the equivilent of "Get(LayoutTableName)::Name" But I can't get it to work.

 

ANY solutions out there?!?!?!?

Share this post


Link to post
Share on other sites
Maarten Witberg

I'm not sure what you're trying to achieve.

 

If you are trying to pick up field content, have you tried GetField( ) ?

 

If you want to dynamically reference a field to set a value, then looping through the fields in the layout and testing them is the only way as far as I know.

Code:


go to field[first in layout]

loop

if[some_test]

#do something to the field, e.g.

set field[#to some value, do not specify the field name]

end if

exit loop if [status(currentfieldname)=LastFieldInTheLayout]

go to field[next]

end loop


kjoe

 

ps status( ) = v6 speak for get( ) functions, GetField is same in both

Share this post


Link to post
Share on other sites
comment

In addition to GetField() and Get(ActiveFieldName), there is also the FieldNames() function, that provides a list of fields on the specified layout. The list can be parsed to extract the desired field reference.

 

However, it is not possible to specify by calculation which field to set in the Set Field[] script step - if that is your question.

Share this post


Link to post
Share on other sites
Maarten Witberg

I'm wondering why this still is not the case. I would have expected this functionality to be added in 7. Would make life just that much easier using go to field, set field and insert calculated result.

 

kjoe

Share this post


Link to post
Share on other sites
comment

I've been wondering about that since version 3. I believe this, along with event script triggering, is at the top of the requested features list.

Share this post


Link to post
Share on other sites
Maarten Witberg

I have some good news and some bad news. I succeeded in making a script that uses dynamic field referencing through Perform Applescript [ ].

The good news is, that this took 15 lines of code (10 of scriptmaker + 5 applescript) whereas getting the same result using just scriptmaker code took (me) 45 lines.

 

So I took both to the test on this file of 1000 records. The bad news is, that the filemaker script still was faster by far, up to over nine times as fast (3 to 6 seconds compared to 27 to 29) in fact.

I'm guessing that this has much to do with applescript being interpreter code, but a different interpreter that Scriptmaker. So I'm wondering how the procedures would compare if I called a compiled applescript from filemaker and do the whole show from there. If I ever succeed doing that, i'll post.

 

I attached the sample for all to see. It's just a silly procedure of picking the highest value of four random values and then storing that value in a field that corresponds to that value.

 

Some more good news -on a personal note- is that I discovered how Freeze Window will seriously speed up loop scripts. It halved the time using the applescript and it reduced the normal script run five to tenfold. smile.gif

 

kjoe

 

PS using yet another scriptmaker-only script that utilizes a double loop (loop through records then loop through fields such as in my first post above) takes 17 lines of code and runs 1000 records in 6 seconds. the longest script is still the fastest... hmmmm.

Share this post


Link to post
Share on other sites
David_Kachel

kjoe,

I downloaded your file and ran it. The reason the AppleScript version takes so long is that you call it inside a loop for each record, making the script compile and run anew for every record. Compilation is what takes so long.

You are correct that a complete AppleScript solution would be much faster, though how much I couldn't say.

Share this post


Link to post
Share on other sites
Maarten Witberg

Hi David,

 

thanks.

 

I have now tried two more options. One is run an interpreter version inside Scriptmaker that performs the full loop, and one where Scriptmaker script calls a compiled script using Send Apple Event.

 

The first option takes 35 seconds for 1000 records, the second option.... well.... what happened is this. The applescript not being wrapped inside a "begin-end transaction" which suspends filemaker, the scriptmaker script clocked a mere second, but the applescript is running in the background and... yes, as I type, it just passes record 900 of 1000 and the clock is at something like ten minutes.... kind of makes you feel like you're in commodore 64 heaven...

 

I thought I had a workaround for field referencing, but it seems that speed is a really big issue. Unless I have written some extremely inefficient code, which is a possibility of course.

 

 

kjoe

 

 

fwiw, here's the applescript code.

 

Code:


tell application "FileMaker Pro"

set NumberOfRecords to the cellValue of cell "gRecordCount" of current record

set a to 1

repeat with a from 1 to NumberOfRecords

set MaxValue to the cellValue of cell a of field "TempStore1"

set FieldRef to "Ref" & MaxValue

set cellValue of cell a of field FieldRef to MaxValue

set a to a + 1

end repeat

end tell

 


 

TempStore1 is now a calc field that determins the max value.

 

 

 

PS. In trying to include a try- end try and a with transaction block I keep running into errors. Makes me search the net for a good resource on applescripting and filemaker. What I found so far is a couple of forums that don't seem so hot, and some old seeming webpages referring to version 4, 3 and 2. FMI site only has loose items in techinfo and support, not a good basics helper.

I welcome any tips on sites and books.

Share this post


Link to post
Share on other sites
Spice Boy
Is there a way for FileMaker to accept a field name in a script that's defined with a syntax similar to.... "Get(LayoutTableName)::FieldName"

 

I take the answer is no...

 

I'd like to use this for a generic script that would put the contents of a field (eg Order_no) into a global variable and then perform a Find in the Orders table.

Share this post


Link to post
Share on other sites
AHunter3

For anyone trying to write a script that needs to Set Field [, "SomeValue"], here's a FileMaker 8.5 work-around that, while still klunky, are at least better than a zillion nested If / Else Ifs.

 

 

FileMaker 8.5:

Put the relevant fields on an "All Fields" form layout and give each field its own table and fieldname as its Object Name. Repeat for each table in the solution. Give the layouts names easily calculated from the native table names.

 

Now you can calculate the table name and/or the field name via whatever calculation algorithms you've got going, and then use Go to Layout [$CalculatedLayoutName] or Go to Related Record [$CalculatedTO] based on your script's calculations followed by Go to Object [$CalculatedFieldName]. Then you do a Set Field [, "SomeValue"] and it sets whatever field is the current active field, which would be the Object you just went to.

 

Earlier Versions:

For you FileMaker 7 and 8.0 folks (and 4 and 5 and 6 folks for that matter), you can use a global instead of the $variable, and use the older/messier strategy of having all the fields in the tab order and looping and using Go to Next Field and exiting loop when Get(FieldName) = Globals::g.CalculatedFieldName, and then once again Set Field [, "SomeValue"].

Share this post


Link to post
Share on other sites
This thread is quite old. Please start a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  



×
×
  • Create New...

Important Information

Terms of Use