问题
I have a FileMaker 18 database that interfaces with an external software. To do so, I need to do the following and can't figure it out:
- export selected data from the currently active record (and only that record)
- import data that's related to the current record into several tables
In the UI I have two buttons, one to export, one to import. What I can't figure out is:
- how to export only the current record, no others? (I managed to get an export, but of all the data in the table)
- how to have a script import data into multiple tables (3 different ones), properly relate them to each other (one is the main table, the others relate to it, 1:n relations) and then relate the main table record to the currently active record that I imported it into?
(second part of the question split off with more details here: importing complex XML data into multiple FileMaker tables)
回答1:
To import inter-related data (e.g. parent and child data) that doesn't have a unique key linking parent and child at the source, import it into a "flat" temporary table first. Then assign a unique key to each group of children and create a corresponding record in the parent table.
To link the imported records to the current record, start by storing the current record's ID in variable. Then assign this value to a field in the parent (I presume?) table.
These are general guidelines. It's hard to be more specific without a specific example. You say you need to import into 3 tables, but I only see 2 (Results and DataPoints).
Note that when importing an XML document, you can do part of the necessary work in the XSLT stylesheet used for the import.
回答2:
To export the current record only, first choose the show all records command and then the omit record command and then the show omitted only command and finally export the one record. This can be scripted.
To import into several tables, make sure you have a primary key that you import into the child tables and that your relations are set up in the relationship graph. Do one import for each table.
Update after clarification:
Ok, looks like you have to do 2 or 3 imports, depending on how many data point tables you have. This can all be done in 1 script. Looks like you will need 3 (or 2) tables, one for the external main and 2 (or 1) for the datapoints as far as I understand from your description. This procedure will work if you only have 1 record in the main table you're importing, as you say you do.
Steps:
- Import the main table into a suitable table that has an auto enter primary key. Set a variable to hold the primary key generated after import.
- Import each of the secondary records into their respective tables. These tables need to have a field available for the foreign key that relates to the primary key in the table in step 1. Do a Replace Field Contents on these records after import to populate the foreign key fields with the variable set in point 1.
- Back in your main table, set the foreign key field for the current record to the variable set in step 1.
Make sure all these tables are related properly in the relationship graph. This should do it.
来源:https://stackoverflow.com/questions/62256971/export-and-import-date-from-into-current-record-only-in-filemaker-18