Ocean West Posted June 21, 2009 Posted June 21, 2009 in a database that has only one table and only one layout i am trying to get record counts from referenced filemaker tables. this is what I have so far, but I am having a hard time getting the result of applescript to trigger. of note this table would contain a record for every table with a field that is the table name that I am trying to get counts for. tell application "FileMaker Pro Advanced" tell document "myDatabase" set rec to ID of current record as integer tell table "referenceTable" set recCount to count records end tell tell table "logTable" set cell "recCountField" of record rec to recCount end tell end tell end tell my goal would to loop thru my records setting the total record count based on the table name that is in the field. hope this makes sense...
Ocean West Posted June 21, 2009 Author Posted June 21, 2009 ok got this working "tell application "FileMaker Pro Advanced 10"¶ tell document "UPGRADE"¶ tell table "old." & IMPORT::Table Name& ""¶ set old to count records¶ end tell¶ tell table "new." & IMPORT::Table Name& ""¶ set new to count records¶ end tell¶ set rec to ID of current record as integer¶ set field "sourceCount" of record ID rec to old¶ set field "targetCount" of record ID rec to new¶ end tell¶ end tell" I have this in a looping script it seems to work wonder if there is a more elegant? s
Fenton Posted June 21, 2009 Posted June 21, 2009 I think that trouble is that you are only specifying the table of the other database, but you are not specifying which database that is. You'd need: tell table "referenceTable" of database "Some name" If you're counting total records you'd want to use "database", not "document" in this line, as the document is the found set (or specific record), but the database is all records. It also is not happy if you put the "tell" command to the other file inside a "document" or "tell current record" tell block of the current file. But you don't really need to use those explicit tell commands for the cells of the current record of the current layout of the current document. I think this is how I'd do it, simplest, if the fields are on the current layout, and you're on the relevant record. tell application "FileMaker Pro Advanced" set table_name to cell "Table_name" of current record set db_name to cell "DB_name" of current record tell table table_name of database db_name to set recCount to count records set cell "recCount" of current record to recCount save record end tell
Fenton Posted June 21, 2009 Posted June 21, 2009 An AppleScript loop (looks a lot like a FileMaker loop :-) tell application "FileMaker Pro Advanced" go to 1st record set recs to count records repeat recs times set rec_num to (ID of current record as integer) + 1 set table_name to cell "Table_name" of current record set db_name to cell "DB_name" of current record tell table table_name of database db_name to set recCount to count records set cell "recCount" of current record to recCount if rec_num ≤ recs then go to record rec_num end if end repeat go to 1st record save record end tell
Ocean West Posted June 21, 2009 Author Posted June 21, 2009 (edited) i don't have a field / cell with the DB name... Database Name: UPGRADE Table Name: IMPORT Table Name: old.tableName // this is a TO to reference file Table Name: new.tableName // this is a TO to reference file fields on the IMPORT table tableName oldCount newCount Since i am already in a loop and need to set other stuff i was going to perform the applescript on each record after I import data. also Do you know of a way to use applescript to get the NextSerialNumber? Edited June 21, 2009 by Guest
Fenton Posted June 21, 2009 Posted June 21, 2009 (edited) Not directly. AppleScript only has access the basics of FileMaker. It could get the Serial number of the last record in a database (then add 1). But that is not quite the same in all cases as GetNextSerialValue. But GetNextSerialValue is a Design function, which uses Text values. It was designed that way so it could do what you want to do, retrieve values from another file which you may have no connection to. P.S. But yeah, that kind of makes the AppleScript I uploaded awkward, as it would have to do that via a "do script FileMaker script" call, in the middle of everything. So, I would do as you are doing, run this on one record at a time, managing the Loop with FileMaker; not an AppleScript loop (which has no particular advantage anyway; not the way I wrote it anyway). Edited June 21, 2009 by Guest
Ocean West Posted June 23, 2009 Author Posted June 23, 2009 thanks Fenton, one more question what about deleting all records in a particular table?
Recommended Posts
This topic is 5631 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now