9 Replies Latest reply on Aug 23, 2012 8:25 PM by MarcDolley

    Nested Duplication of Related Records

    russbrad

      So I've successfully got duplication with related records working, and a slightly trickier version involving creating new records:

       

      https://fmdev.filemaker.com/message/90759

      https://fmdev.filemaker.com/message/92148

       

      However, now I'm trying to duplicate a record, with related child records, and a second level of related child records, which are grandchild records of the original record.

       

      Here's the pseudo-code:

       

      1. Duplicate source record
      2. Go to related child records
      3. 1st-level loop
        1. Duplicate record
        2. Go to related grandchild records
        3. 2nd-level loop
          1. Duplicate record
          2. Go to next record
        4. Go to next record
      4. Go to duplicate record
      5. Profit

       

      It's at step 3D that I run into a problem. I don't know how to return to the found set that I established at step 2. It seems to me that step 3B clears the existing found set, but if that's not the case, I'd like to know how to return to the previous found set.

       

      Message was edited by: russbrad

        • 1. Re: Nested Duplication of Related Records
          comment

          What exactly does "second level of related child records" mean?

          • 2. Re: Nested Duplication of Related Records
            russbrad

            Sorry, that should have been clearer.

             

            Table A has related child records from Table B, which must be duplicated.

             

            Table B has related child records from Table C, which must also be duplicated.

             

            So if Table B contains child records of Table A, then Table C contains grandchild records of Table A.

             

            I've updated the original post to clarify.

            • 3. Re: Nested Duplication of Related Records
              MarcDolley

              I've just been working on the same process. You haven't actually lost your found set. You just need to go back to the layout you were on at step 3A and it will still be there. I'm assuming you simplified that process for the sake of your post and have included all of the set variables etc.

               

              This does work, but loops within loops can be risky. Make sure you include lots of error trapping. You need to check that there are actually related granchild records before duplicating otherwise the script will act where it is and could make a mess of your data.

               

              Above all, test and test again.

               

              Regards

              Marc

              • 4. Re: Nested Duplication of Related Records
                russbrad

                That was it!  Part of the problem, which I wasn't noticing, was that I was performing a search in step 3A to get back to the source child record, which was clearing my found set.  Instead I stored the record number and located the record using that number.  This is a much more sane way of navigating back to records.  I didn't understand it before, because my understanding of found sets was lacking.

                 

                So to clarify about found sets, their scope is a particular layout?  So each layout has a particular found set associated with it?  I've looked for this information in the documentation, but I haven't been able to find it.

                • 5. Re: Nested Duplication of Related Records
                  MarcDolley

                  I wouldn't say that their scope is a particular layout. It's more about it being a sequential process happening within a single script. You start with the parent record then go to the related child records on a different layout and loop through them. Within that loop is another (nested) loop which is going to the related grandchild records on a third layout. When that loop is finished, going back to the second layout will still show the same found set as when you left it. That's assuming that nothing in your script has altered the found set along the way.

                   

                  As long as you have the sequence correct and the necessary error trapping, the process should work every time.

                   

                  Marc

                   

                  P.S. Always a good idea to add lots of comments in your script in case you have to re-visit it later and can't remember the sequence.

                  • 6. Re: Nested Duplication of Related Records
                    comment

                    russbrad wrote:

                     

                    So to clarify about found sets, their scope is a particular layout?  So each layout has a particular found set associated with it? 

                     

                    A found set belongs to a specific TO in a specific window.

                    1 of 1 people found this helpful
                    • 7. Re: Nested Duplication of Related Records
                      russbrad

                      Thanks for that, this has been really baffling me until now.  Is this information documented somewhere?  So if I have a similar question in the future I can go there to find it?

                       

                      It just seems odd that in all the documentation I've read and the tutorials I've done, the seemingly fundamental information of what a found set is and exactly how it behaves has not been laid out anywhere.

                      • 8. Re: Nested Duplication of Related Records
                        comment

                        It may be documented in the help - I am not really sure.

                        • 9. Re: Nested Duplication of Related Records
                          MarcDolley

                          It's probably because 'Found Sets' are really just a temporary state of the database. A table consists of data which may or may not be in one part or two (the found set and the omitted set). The existence of a found set is determined by the user or by a scripted process. As a developer, if you script a process of creating a found set in a table, it will remain that way until some other script step alters it. Knowing that should help you better understand how to manage found sets within your script. Scripts are essentially follow a linear path from beginning to end.

                           

                          Regards

                          Marc