FileMaker Pro 2026 - get persistent data names
|
I have mentioned in previous emails that there is a function missing for persistent data. While there is a function ListPersistentDataIDs to list all the instance IDs for a specified name, there is no function to list all the names used in persistent data entries. Hopefully this is an oversight and we will eventually get a function like ListPersistentDataNames. In the meantime how do we retrieve all the names currently being used for persistent data entries in a file? XML Catalog FileThere is a function in the Tools menu called "Save a Copy as XML…". This allows us to export FileMaker catalog descriptions as XML files. The UI has been improved in FileMaker 26 and now enables saving each catalog to an individual file. With the new persistent data in FileMaker 26 comes a new catalog – Persistent Data Store. This catalog contains XML descriptions of all persistent data entries in a file. A single persistent data entry looks like this:
You will note that the first line contains the name and instance ID used to identify the entry. Along with the Tools menu command, there is an equivalent script step – Save a Copy as XML. This script step has options to specify a destination file (path and name) and to set export options as JSON. This JSON allows us, among other things, to specify which catalogs to export. This is the first step in a scripted solution to produce a list of persistent entry names. Read the XML fileThe next step is to read the content of the XML file. This can be done using the Data File script steps. We simply open the data file, read from the data file, and close the data file. The contents are read into a variable. Parse and store the list of namesThe last step is to parse the entry names out of the XML that has been read. This is reasonably easy using a While function to process the lines of XML. We will look for instances of <PersistentStore name= and extract the name following that string. This will produce a return-separated list of names. If a particular name has been used for several instance IDs, then there will be repetition in the list. So we can reduce that list to unique names only using the UniqueValues function. The final list can be stored in a field. Show me the scriptThe final script looks like this:
Note that this script is required to run with Full Access to be able to generate the XML file. The script starts by setting a variable to the path of the XML file to be exported. For convenience we are storing it in a temporary path since we don't need to keep the file. The Persistent Data Store catalog is then saved as XML. This script step uses Specify options as JSON. The standard JSON provided by FileMaker has been modified such that the only catalog being exported is PersistentStoreCatalog. The exported XML file is then opened, read into a variable ($xml), and closed. Note that when reading from the data file, we are not specifying a number of bytes – leaving Amount (bytes) blank causes FileMaker to read the entire document. Also note that we are reading as UTF-8. The names list is then parsed from the XML into another variable ($namesList). This uses the following calculation:
* Calculation optimised on advice from Giulio Villani – thanks :) Finally the names list is reduced to unique values only, sorted into alphabetical order, and stored in a field. Job doneWe now have a list of all the unique names currently used in persistent data entries in the file. It is admittedly more complex than using a simple function to retrieve the list of names but we can only hope for that to come soon. We can run the script any time we need to ensure that we have a fully up-to-date list. So what are we going to do with this list of names? There are a lot of uses. For example:
What would you use the persistent data names list for?
|