Error on repeat loop through Filemaker database records

I am trying to cycle through records from one table of a multi-table database and assign the field contents from a field called “ProposalID” to a variable called “proposalID”, but I keep getting an error ("Object not found: # -1728). It’s not clear to my what I’m doing wrong. Any help would be greatly appreciated.

Here’s the code.


tell application "FileMaker Pro"
	tell database "MyDatabase"
		activate
		repeat with thisRecord in every record of table "Proposals"
			set proposalID to cellValue of cell "ProposalID" of thisRecord --this is where the error occurs
		end repeat
	end tell
end tell

Hello.

I have no experience in scripting FileMaker Pro. But seeing that error -1728 brings back some memories of missing references. You are within FileMaker Pro’s tell block but still you may need to tell it that the objects is it’s own.
I think what happens is that it looks for the objects in the top level scope of your script and can’t find them there.

Having already made up for errors that maybe aren’t there I’ll continue with the next.
thisRecord holds a reference to the current record of the table “Proposal” you may need to use the contents of clause to get access to what that reference actually contains.

Try this:


tell application "FileMaker Pro"
	tell database "MyDatabase"
		activate
		repeat with thisRecord in (get its every record of its table "Proposals") -- for Speed.
			set proposalID to cellValue of cell "ProposalID" of contents of thisRecord --this is where the error occurs
		end repeat
	end tell
end tell


I hope this helps

Best Regards

McUsr

Hi McUsr,

Thank you so much for your help. Unfortunately, your solution doesn’t seem to work. I’ve been playing with some utility scripts to see how thisRecord is being handled by the script–but it’s not clear to me what’s happening. For whatever reason, whenever I try cellValue on thisRecord, the object is not found (same basic error in your code). The following code works and does what I need it to do–but it feels a bit like cheating!


tell application "FileMaker Pro"
	tell database "MyDatabase"
		tell table "Proposals"
			set numberOfProposals to count every record
			set recordContents to {}
			set recordContents to every record
			repeat with i from 1 to numberOfProposals
				set thisRecordItem to item 1 of (item i in recordContents) -- item 1 is the ProposalID cell
				set proposalID to (thisRecordItem as integer)
			end repeat
		end tell
	end tell
end tell

I’m not sure what exactly you want to return/do with the field. But I think I see what the problem may be. When you ask FileMaker for a record, it returns ALL the fields. Then it is not only large, but just a list of data.

Also, there are 2 basic ways to ask FileMaker for data, either “database” (all records) or (“document” or “window”), which is the found set. The term “field” is for “database”, “cell” is for “document” (though it works with database also).

What works is to get a list of the record IDs, then loop thru them, targeting each record by ID. If you’re just trying to get a list from a field, in either all records or a found set, it can be done without a repeat. Here’s some possibles (my file, my names, same thing):


-- return a field's values from the found set (omitted 1 record)
tell application "FileMaker Pro Advanced"
	tell document "CompanyBranches"
		-- activate
		set recIDs to ID of records of layout "Companies"
		set company_id_list to {}
		repeat with recID in recIDs
			tell record ID recID
				set end of company_id_list to cell "CompanyID"
			end tell
		end repeat
		-- return company_id_list
		-- {"001", "002", "003", "004", "005"}
	end tell
end tell

-- Or, shorter version
tell application "FileMaker Pro Advanced"
	tell document "CompanyBranches"
		-- activate
		set companyIDs to cell "CompanyID" of records of layout "Companies"
		-- {"001", "002", "003", "004", "005"}
	end tell
end tell

-- Or, all records
(*
tell application "FileMaker Pro Advanced"
	tell database "CompanyBranches"
		-- activate
		set companyIDs to field "CompanyID" of table "Companies"
		-- {"001", "002", "003", "004", "005", "006"}
	end tell
end tell
*)