21 Jan 2021: demo has been updated to fix a couple bugs; article has been updated to reflect these changes.
Demo file: file ids, table ids and field schema, v4.zip (requires FM 18 or later)
INTRODUCTION
Recently I was asked to help document a FileMaker solution by creating and populating a “schema” table as per the above screen shot.
One of the requirements was to programmatically determine internal ID numbers for the file and for the tables (as opposed to table occurrences) within that file, and this was accomplished by leveraging some script steps that were introduced in FileMaker 18.
(Thank you Rob Russell for pointing me in the right direction, i.e., to Save A Copy As XML.)
RUNNING THE DEMO
Clicking this button…
…invokes this script…
…which, in a nutshell, does the following:
- Saves as XML to the Documents folder
- Uses one of two methods to read the XML file into $xml.content
- If FM 18 on Windows, uses Insert From URL
- Otherwise uses Read From Data File to load the first 10,000 bytes
- Deletes the XML file from the Documents folder
- Parses file and table data from $xml.content into the schema table
- Uses SQL to populate field entries, as per this informative article by Andrew Duncan: Using ExecuteSQL to Query the Virtual Schema/System Tables.
CLOSING THOUGHTS
Beyond the narrow use case of today’s article, perhaps the real take away is how easy it now is to pull data from an external file into a variable using native FileMaker tools only, as opposed to relying on plug-ins or any other outside technology.