8 Replies Latest reply on Dec 3, 2013 6:33 PM by Datagrace

    creating records in a related table

    wellman_jill

      I have a toc (OWNERS) related to an initially empty toc (printLABELS)

      I want to create a record in the printLABELS table from the OWNERS table

       

      Is there an easier, more elegant way to do this than simply looping over OWNERS, going to printLABLES table, to create the new related record?

       

      Thanks for any help

       

      Jill Wellman

        • 1. Re: creating records in a related table
          erolst

          Are you talking about a one-off initializing operation to populate an empty table?

           

          If you want to create one label for each existing Owner, simply "Show all" owner records, go to the Labels TO and import the records from the owner TO; all you need to import is Owner primary ID into owner foreign ID so each record is related back to an owner record.

          • 2. Re: creating records in a related table
            Datagrace

            Are you familiar with using 'Allow creation of records in this table via this relationship.'? While generally employed with portals, it need not be. You can set any modifiable field in the child table to a valid value, using whatever means are appropriate, and a new child record will be created. The child record's foreign key will have the correct value. It is a powerful tool, useful in many situations where you do not want to leave the oriiginal context.

             

            John Weinshel

            • 3. Re: creating records in a related table
              ChadAdams

              FileMaker gives us so many techniques to create records it really will depend on what you prefer and what is best for each situation.

               

              Assuming there is a relationship between OWNERS and printLABELS that is something like OWNERS::ID to printLABELS::ID_Owners, then you can:

               

              1. Get the found set of OWNERS you want, go to printLABLES and import

              2. Get a list of OWNER IDs (set to a variable), go to printLABLES and using a loop create a printLABEL for each OWNER in the list

              3. Setup a relationship to "Allow creation of records in this table via this relationship" and set a field in printLABELS to create the record

              4. Loop over the OWNERS going to printLABELS for each one and creating a record (one at a time, rather than in a batch as described in #2)

               

              I would lean toward writing a stand alone script that would create a printLABELS record and pass it parameters for the OWNER that I wanted to link it to.  I'd write it in such a way that it could handle one OWNER ID, or a list of OWNER IDs.  This would allow me to call this script from anywhere in my system when I needed to create a printLABELS record.  And allowing a list would let me  create multiple printLABELS when I needed without having to go back and forth between OWNERS and printLABELS for each one.

               

              Hope that helps,

               

              Chad

              • 4. Re: creating records in a related table
                wellman_jill

                This sounds like just what I'd like.

                I've used this many times with a portal by using new portal record or clicking in an empty portal row

                 

                ----

                I didn't make clear in my previous post

                The labels table contains relatively little of the  OWNERS records information.

                   LABELS contains formated text from OWNERS, and things like label size.

                 

                ---

                I'm going to try this out right now

                 

                thanks

                Jill

                • 5. Re: creating records in a related table
                  wellman_jill

                  Awesome ==  I kind of knew it had something to do with Creating through a relationship.

                  But I was stuck in portal thinking

                   

                  This works like a charm!!!

                  • 6. Re: creating records in a related table
                    erolst

                    wellman_jill wrote:

                     

                    The labels table contains relatively little of the  OWNERS records information.

                     

                    Actually, being related records, they should contain none of the Owner's records information, except for the primary key.

                    • 7. Re: creating records in a related table
                      wellman_jill

                      Absolutely right.

                       

                      What the lables table has are fields of text (calculated from OWNERS))

                      formated to display on labels of varying size.

                       

                      Good point -- helps keep my head straight.

                       

                      Thanks

                      • 8. Re: creating records in a related table
                        Datagrace

                        In a perfectly normalized world, you are correct that the child table holds none of its parent's data. It's possible the OP is working in a less perfect world.

                         

                        John Weinshel