Can't get past the first record set in Filemaker Pro

And don’t I feel foolish? Ok, here is the script I am using that KIND OF works…

-- on sVerifyExists(lDBCompany,lFName,lMName,lLName,lDBPassword,lAddress1,lCity,lState,lCountry,lZipCode)

set lDBPath to "Macintosh HD:Applications:Design-Mo-Tron:Components:DMT Database" -- Pass (gDMTFolder&"Components:DMT Database")
set lAuthorized to "false" -- Keep
-- Begin test data
set lDBCompany to "Dillinger Pastries Inc."
set lFName to "John"
set lMName to ""
set lLName to "Dillinger"
set lDBPassword to "muffins"
set lAddress1 to "2345 Test Ave."
set lCity to "Wixom"
set lState to "MI"
set lCountry to ""
set lZipCode to "26545"
-- End test data

tell application "FileMaker Pro"
	activate
	open file lDBPath
	
	tell table "Owner_Info" of database "DMT Database"
		show (every record whose (cell "Company_Name" = lDBCompany))
		
		if (cell "Owner_Address_1" = lAddress1) ¬
			and (cell "Owner_City" = lCity) and (cell "Owner_State" = lState) ¬
			and (cell "Owner_Country" = lCountry) and (cell "Owner_Zip" = lZipCode) then
			set lOwnerID to (cell "Owner_ID")
			
		else
			set lOwnerID to 0
		end if
		
	end tell
	
	tell table "Owner_Info" of database "DMT Database"
		if (cell "Owner_ID" = lOwnerID) and (cell "Owner_FName" = lFName) ¬
			and (cell "Owner_MName" = lMName) and (cell "Owner_LName" = lLName) ¬
			and (cell "Owner_Password" = lDBPassword) then
			set lAuthorized to "true"
		end if
	end tell
	
	tell table "Authorized_Users_Info" of database "DMT Database"
		if (cell "Owner_ID" = lOwnerID) and (cell "AU_FName" = lFName) ¬
			and (cell "AU_MName" = lMName) and (cell "AU_LName" = lLName) ¬
			and (cell "AU_Password" = lDBPassword) then
			set lAuthorized to "true"
		end if
	end tell
	
	return lAuthorized
end tell

-- end

Now the database is comprised of 7 related tables all feeding into table “Owner_Info”. I have triple and quadruple checked my relationships and for all I can tell everything in the database is working fine. What seems to be happening is that in any given table I access via applescript I can only see the first record in the table - I know this because the data I am seeking in this test is in record 2. I also can not venture past the first related Phone record, the first related Email record, or the first related Authorized User record. I tried a repeat loop like:

repeat with i from 1 to count records
			set lRecordList to get data record i...

but it only looped through the FIRST record in the table (count records) times. I have considered setting the data as a list and pulling the items from it but the problem with that approach is that one day I or someone else will reorder the fields and then the script will have to be rewritten. I would avoid that if I could. All the script above is attempting to do is check in the table “Owner_Info” and in the table “Authorized_Users_Info” to see if the person sending the job order is authorized to do so, and so far it only works for the first records owner and authorized user - everyone else is screwed.

I imagine my error is somewhat basic for anyone on this board familiar with scripting Filemaker Pro so just to save you some time if you wonder why I did something that is flat out wrong or went about something in a incredibly circuitous manner it is because I didn’t know any better way. Believe me - I have been looking on the web, reading through dense tomes, and experimenting with any collection of commands that strike me as being even remotely possible. No luck.

Thanking you in advance for any aid you might render.’

Maybe my question makes no sense or maybe I did not supply enough information for anyone to make an educated guess. Can anybody point me to a tutorial or a script I can learn from? It’s frustrating that I can manage to search my database for records but can’t get past the first one, makes no sense.

The database knows there are only two records because if I try to go to record 3 I get an object does not exist error, yet if I run a repeat loop to check record x in BOTH cases it only looks at the data from record 1 - twice. No kind of sense. :confused:

Well, this is what I FINALLY came up with and it DOES work… but there’s a whole lotta looping going on.

-- on sVerifyExists(lDBCompany,lFName,lMName,lLName,lDBPassword,lAddress1,lCity,lState,lCountry,lZipCode)

set lDBPath to "Macintosh HD:Applications:Design-Mo-Tron:Components:DMT_DB" -- Pass (gDMTFolder&"Components:DMT_DB")
set lAuthorized to "false" -- Keep
set lDBCompany to "Dillinger Pastries Inc."
set lFName to "John"
set lMName to ""
set lLName to "Dillinger"
set lDBPassword to "muffins"
set lAddress1 to "2345 Test Ave."
set lCity to "Wixom"
set lState to "MI"
set lCountry to "US"
set lZipCode to "26545"

tell application "FileMaker Pro"
	activate
	open file lDBPath
	
	tell database "DMT_DB"
		
		tell table "Owner_Info"
			
			repeat with a from 1 to (count records)
				tell record a
					
					if (cell "Owner_Address_1" = lAddress1) ¬
						and (cell "Owner_City" = lCity) and (cell "Owner_State" = lState) ¬
						and (cell "Owner_Country" = lCountry) and (cell "Owner_Zip" = lZipCode) then
						set lOwnerID to (cell "Owner_ID")
						
						if (cell "Owner_ID" = lOwnerID) and (cell "Owner_FName" = lFName) ¬
							and (cell "Owner_MName" = lMName) and (cell "Owner_LName" = lLName) ¬
							and (cell "Owner_Password" = lDBPassword) then
							
							set lAuthorized to "true"
							exit repeat
						end if
						
					else
						set lOwnerID to 0
					end if
					
				end tell
			end repeat
			
		end tell
		
		if lAuthorized = "false" then
			tell table "Authorized_Users_Info"
				
				repeat with a from 1 to (count records)
					tell record a
						
						if (cell "Owner_ID" = lOwnerID) and (cell "AU_FName" = lFName) ¬
							and (cell "AU_MName" = lMName) and (cell "AU_LName" = lLName) ¬
							and (cell "AU_Password" = lDBPassword) then
							
							set lAuthorized to "true"
							exit repeat
						end if
						
					end tell
				end repeat
				
			end tell
		end if
		
	end tell
	
	return lAuthorized
end tell

then the event log says:


tell application "FileMaker Pro"
	activate
	open file "Macintosh HD:Applications:Design-Mo-Tron:Components:DMT_DB"
	count every record of table "Owner_Info" of database "DMT_DB"
		2
	get cell "Owner_Address_1" of record 1 of table "Owner_Info" of database "DMT_DB"
		"10057 N. Linden Rd."
	get cell "Owner_Address_1" of record 2 of table "Owner_Info" of database "DMT_DB"
		"2345 Test Ave."
	get cell "Owner_City" of record 2 of table "Owner_Info" of database "DMT_DB"
		"Wixom"
	get cell "Owner_State" of record 2 of table "Owner_Info" of database "DMT_DB"
		"MI"
	get cell "Owner_Country" of record 2 of table "Owner_Info" of database "DMT_DB"
		"US"
	get cell "Owner_Zip" of record 2 of table "Owner_Info" of database "DMT_DB"
		"26545"
	get cell "Owner_ID" of record 2 of table "Owner_Info" of database "DMT_DB"
		"2"
	get cell "Owner_ID" of record 2 of table "Owner_Info" of database "DMT_DB"
		"2"
	get cell "Owner_FName" of record 2 of table "Owner_Info" of database "DMT_DB"
		"John"
	get cell "Owner_MName" of record 2 of table "Owner_Info" of database "DMT_DB"
		""
	get cell "Owner_LName" of record 2 of table "Owner_Info" of database "DMT_DB"
		"Dillinger"
	get cell "Owner_Password" of record 2 of table "Owner_Info" of database "DMT_DB"
		"muffins"
end tell

I am happy it works now but am well aware of how slow this will be when I have 50 records or 100 records even to parse through. Ganesha save me when I get into the several hundreds of records! I really wanted to make the ‘whose’ command work for me because I suspect it would save much time but as I said above… blah, blah, blah. If anyone has a better suggestion lay it on me but until then I go with what I got. :expressionless:

You can use this to target specific records in the current found set. Do a “show all” if you need all records included:

set recordIDList to get ID of every record whose cell "whateverCell" = "whateverCriteria"

This will return a list of record ID’s. Then you can loop through the necessary records using the ID as a reliable reference:

repeat with i from 1 to count of recordIDList
		set x to cell "whateverCell" of record ID (item i of recordIDList)
		end repeat

Accessing a DB over a network, I just pulled specific fields from 588 out of 9500 records in about eight seconds.

Hope this helps.

-N

Thanks nedloh99,

At one point I remember playing around with getting the record ID but was getting an error (the text of which I cannot remember). I probably had it in the wrong location or wasn’t using it correctly so I will try your syntax and report back.

Currently I only have two test records in the database and it takes about 1 second to return the requested result. I know that the sample is too small to make any reasonable judgements as to the speed but it sems slower than it should be. Hell, in two seconds I could locate the data in the layout myself.

Huh, apparently the post from last night didn’t take… and it was by far my most brilliant and insightful one yet! Darn the luck.

Anyhoo, I took the code suggestion you gave me N and this is how it looked:

set lDBPath to "Macintosh HD:Applications:Design-Mo-Tron:Components:DMT_DB" -- Pass (gDMTFolder&"Components:DMT_DB")
set lAuthorized to "false" -- Keep
set lDBCompany to "Dillinger Pastries Inc."
set lFName to "John"
set lMName to ""
set lLName to "Dillinger"
set lDBPassword to "muffins"
set lAddress1 to "2345 Test Ave."
set lCity to "Wixom"
set lState to "MI"
set lCountry to "US"
set lZipCode to "26545"

tell application "FileMaker Pro"
	activate
	open file lDBPath
	show every record
	
	tell database "DMT_DB"
		
		tell table "Owner_Info"
			set lRecordIDList to (get ID of (every record whose (cell "Company_Name" = "lDBCompany")))
			
			repeat with i from 1 to count of recordIDList
				set lOwnerID to cell "Owner_ID" of record ID (item i of recordIDList)
				
				if (cell "Owner_ID" = lOwnerID) and (cell "Owner_City" = lCity) ¬
					and (cell "Owner_State" = lState) and (cell "Owner_FName" = lFName) ¬
					and (cell "Owner_LName" = lLName) and (cell "Owner_Password" = lDBPassword) then
					
					set lAuthorized to "true"
					exit repeat
					
				else
					set lOwnerID to 0
				end if
				
			end repeat
			
		end tell
		
		if (lAuthorized = "false") then
			tell table "Authorized_Users_Info"
				
				repeat with a from 1 to (count records)
					tell record a
						
						if (cell "Owner_ID" = lOwnerID) and (cell "AU_FName" = lFName) ¬
							and (cell "AU_MName" = lMName) and (cell "AU_LName" = lLName) ¬
							and (cell "AU_Password" = lDBPassword) then
							
							set lAUID to (cell "AU_ID")
							set lAuthorized to "true"
							exit repeat
						end if
						
					end tell
				end repeat
				
			end tell
		end if
		
	end tell
	
	return lAuthorized
end tell

but the problem is that the event log said:

tell application "FileMaker Pro"
	activate
	open file "Macintosh HD:Applications:Design-Mo-Tron:Components:DMT_DB"
	show every record
	get ID of every record of table "Owner_Info" of database "DMT_DB" whose cell "Company_Name" = "lDBCompany"
		"FileMaker Pro got an error: Event not handled."

So then I decided to try to change line set lRecordIDList to (get ID of (every record whose (cell “Company_Name” = “lDBCompany”))) to read set lRecordIDList to (get record ID of (every record whose (cell “Company_Name” = “lDBCompany”))) but then that wretched event log said:

tell application "FileMaker Pro"
	activate
	open file "Macintosh HD:Applications:Design-Mo-Tron:Components:DMT_DB"
	show every record
	get ID of table "Owner_Info" of database "DMT_DB"
		1.363149E+7
	get record 1.363149E+7 of table "Owner_Info" of database "DMT_DB" whose cell "Company_Name" = "lDBCompany"
		"FileMaker Pro got an error: Event not handled."

First it gives me a table ID I am pretty sure I never asked for and then errors out. Any ideas on what I’m doing wrong?

Well, this stinks.

I wrote a simple script to target a single table within a database, and after getting errors I went and checked out some of my old FM Projects and guess what?

Every single one has a “go to layout” command before using a “whose” clause at the table level. I can seem to do everything EXCEPT use the 'whose" clause unless a layout representing the designated table is active.

I’m going to start a new thread and see if anyone else has an idea.

EDIT: I did a search here and found someone else and had a similar issue and referenced Hanaan Rosenthal’s book. I pulled it off the shelf and it seems he has some scripts published that don’t work that deal directly with this. I wonder if it’s a bug of some sort?

-N

I am using the Rosental book myself which is why I am so baffled. Everything else I have referenced in his book has worked for me so far but this one issue. I am going forward using he repeat loops but might go back when I have the time and see if I can use the layouts to pull the data instead.