3 Replies Latest reply on Dec 12, 2016 10:05 AM by erolst

    Export selected data into a new database

    user28082

      Hello,

       

      It may be a beginner's question, asked already thousands of times, so sorry for that ;-)

       

      I have created a database (based on excel file) and want to export a selection of entries from it into a son database (one field makes the link)

      How shall I write the script to do that ?

       

      I have currently written one, but I have strange results (not all selected fields are created, the last field is missing and/or is an empty entry in the son database, etc...)

       

      Thanks for any hint and advise,

      Bertrand

        • 1. Re: Export selected data into a new database
          mikebeargie

          Assuming you have a primary key in the "parent" table, then you should be able to export all records from the parents table, and import them to the "child" table.

           

          The key is that when you import to the new table, you need the primary key of "parent" imported to the foreign key of "child" to establish the relationship.

           

          The script for this could really just be as simple as:

          Set Variable [ $file ; "file:" & get(temporarypath) & "temp.fmp12" ]

          Export Records [ $file ; filemaker format ; specify fields ]

          Go to Layout [ child ]

          Import Records [ $file ; filemaker format ; specify fields ]

           

          Do you have a proper unique primary key in the parent table, as well as a corresponding foreign key in the child table that makes up the relationship?

           

          Also post a screenshot of your script in the future, so we can better assist.

          • 2. Re: Export selected data into a new database
            philmodjunk

            You might consider this option (Make back up copies first in case it doesn't produce the results  you want):

             

            Find the records either manually or via a script to produce a found set of the desired records.

            Use Import Records to import that found set into your separate table.

            • 3. Re: Export selected data into a new database
              erolst

              Simplest approach:

               

              - Find the records in the source table

              - Go to a layout of the target table

              - Import

               

              Make sure to check the table occurrence of the layout where you performed the find (go to Layout mode and take note of the name next to 'Table:'); that is the name you must select in the Import dialog on the 'Source' side.

               

              At that point, the two tables don't have to be related; in fact, often child records are created by this method. For this, you must not forget to map the foreign key of the import table to the primary key of the export table.

              user28082 wrote:

              a son database

              The common term for the many-side in a ine-to-many relationship is (the gender-neutral) 'child table'.