5 Replies Latest reply on Aug 13, 2009 1:58 PM by timothy2k

    Script Steps to update all related records?

    timothy2k

      Title

      Script Steps to update all related records?

      Post

      I have a table Estimate with a field called estimate_parent_id, and I did a self related table called Estimate 2 based on that field (to keep track ofthe number of duplicates that exist for each parent Estimate).

       

      I want to create a script that runs everytime a duplicate of the parent is created that goes and adds 1 to the "duplicate counter" field in all related parent records to the current count value. Same thing with the deletion of a duplicate (finds all related and removes 1 from the duplicate count in all related records).

       

      Does anyone know the proper script steps to update all found or related records? I'd rather not use a loop if possible.

       

       

        • 1. Re: Script Steps to update all related records?
          ninja
            

          howdy timothy2k,

           

          If you're willing to do without a script altogether, wouldn't the Count() function be of good use here?

          Set up a field called "Count" as a calculation and define it as

           

          Count(SelfjoinedTable::estimate_parent_id)

           

          or did I misunderstand what you are trying to do?

          • 2. Re: Script Steps to update all related records?
            timothy2k
              

            Well, I do have a field that is actually counting the value (dupcounter is a calculated field that does a Count( Estimate 2::estimate_parent_id), and that is working properly (I see the value increase each time I create a dup).  The issue is, when I create a new duplicate, only the NEW record is getting that field populated with the correct count.  I want to make sure that field gets updated for all related records. I thought if it was a calculated field it would auto update the others, but that does not seem to be the case.

             

            Can't use a global (I don't think) because that field is not the same for all records, so I'm guessing I just need to update that field for all related records.

             

            I'm just having issues finding the correct scripting steps that do that.

            • 3. Re: Script Steps to update all related records?
              ninja
                

              Howdy timothy2k,

               

              have you checked the checkbox by "do not store" under the storage options of your calculated field?  It should be unstored.

               

              Adding on:  I don't think I've seen anything that you've posted in this thread that calls for a script.  If this is simply a selfjoined table, you don't need a script, just the count field...I just tried this out on one of my play dbases and it works like you want it to...as long as the "do not store" is checked.

               

              • 4. Re: Script Steps to update all related records?
                timothy2k
                  

                Hmm, is that an option for Filemaker 10 Advanced? I am looking at the storage options and do not see that anywhere.....

                 

                 

                 

                **Silly me, had the field set as a numeric and not a calculation.  The check box was already checked for do not store tho....I'll test again.

                • 5. Re: Script Steps to update all related records?
                  timothy2k
                     Yes, seems to be working as I need it.  A simpler solution is always a better one!