I’m wanting to identify the number of records found in a FileMaker Pro search:
tell database irisSurrogat
set cell "Image Type" of request 1 to "==slide" as text
set cell "Image Type" of request 2 to "==digital image" as text
find window 1
set imageCount to count of record of window 1
end tell
Unfortunately the count I get is the count of total records in the database. Does anyone know how to identify just the number of found records? According to some documentation I have read, count does allow you to identify the number of found records. But that documentation doesn’t provide an example.
Here’s what I see using FileMaker 6.0v4/OS X 10.2.8.
tell application "FileMaker Pro"
-- this returns the total count
set db_count to count records of front database
-- these return the same count (found count)
set docCount to count records of front document
set winCount to count records of front window
end tell
Unfortunately, I’m running the same OS/FM versions and the code you suggest gives me all the records (9129) each time. But I can see that the search when executed via the script found (9109) less than the full record set.
I’ve never had luck using “front document”, I always use “document 1”
tell application "FileMaker Pro"
set recordCount to count of records of database 1
set docCount to count of records of document 1
end tell
{recordCount, docCount}
Also, to get a found count, you HAVE to use document, nothing else works.
I note that there was only one database/document/window open when I tested the code so you might be onto something here. I don’t script FMP often enough to offer much more than general guesses that keep a topic alive until an expert comes along.
I think is this case, you need to think about how all this would happen if you were doing it manually. You would query the DATABASE but the WINDOW would show you the result. This is from a handler that I have used successfully, where db_name is the database name and search_value is (you guessed it) the search value:
tell application “FileMaker Pro”
tell database db_name
go to
show every record
delete every request
create request
set cell cell_name of request 1 to search_value
find
end tell
tell window db_name
set found_count to count of records
end tell
end tell
return found_count
I do quite a bit of AS with both Quark and FileMaker and I almost never refer to “front document”; “document 1” or “current document”. I always try to use the name of the object. That’s probably because I have a hard time keeping track of many documents that are open. All this said, I have to agree with Rob. If you can, create a calculation field for "Status(CurrentFoundCount). It seems to be much more reliable and is the only way I really use anymore. but you need to trap for -1728 error. The same handler re-written looks like this
tell application "FileMaker Pro"
tell database db_name
go to
show every record
delete every request
create request
set cell cell_name of request 1 to search_value
find
try
set found_count to cellValue of cell "found_count"
on error errMess number errNum
if errNum is -1728 then set found_count to "0"
end try
end tell
end tell
return found_count
Although this is slightly off topic, I would like to recommend that if you are sending lots of data to or from FileMaker; try to send one chunk of data to a global field and use FileMaker's scripting to parse it and place it into the correct cell. Then you are only involving one Apple Event (the slow stuff). Your total time required will drop expotentially.[/u]
Thanks for the suggestions. Unfortunately, modifying the database is the last thing desired. It’s an acquired application that we want to avoid modifying.
I’ve gone back to a previous procedure I was trying to use and got that code working and will be using it.
Thanks again for all the suggestions, I’ll keep them in mind if I’m working on an internally built FileMaker application.