6 Replies Latest reply on Jan 27, 2010 5:28 PM by mwtse

    Create record in another table

    mwtse

      Title

      Create record in another table

      Post

      Sorry for unable to phase the Subject line clearly.

       

       

      Suppose I am looping with the records in Table1,

       

      I perform some calculation and want to create a record in Table2. 

       

      What I'm doing now is to use

       

      Go to Layout["Table2" (Table2)]

      New Record/Request

       

      so that the record is created in Table2.

       

      However, it seems to me that it does not make sense because a layout is not the same as a table. I am switching to another layout in order to switch to another table.

       

      My question: Is this the correct way to do it? Is there any other script command that can perform what I want to do? 

       

      Thanks. 

        • 1. Re: Create record in another table
          ninja
            

          howdy mwtse,

           

          You are right, a layout is not a table.  But a layout is a tool through which you can define which table you want the record created in.

           

          IMHO you're doing it right.

           

          The only other way I would consider, and only if it matches what you're trying to do, is to work through a portal on the current layout.  The portal is also a method to define which table you want the record created in.  All things equal, I would GoToLayout.

          • 2. Re: Create record in another table
            mwtse
              

            Hi Ninja,

             

              Am I correct that at the end of the loop, when I am going to advance to the next record of Table1, I have to use Go to Layout["Table1" (Table1)] before the next record script?

              

             

              If I forgot, then I will go into trouble. That is not a very good way to do program! 

            • 3. Re: Create record in another table
              ninja
                

              Howdy,

               

              If you are looping through records in table1 and want to go to the next record in table1, you should have focus on a layout based on table1 before you command to go to the next record.  It doesn't matter a great deal which layout you have the focus on, as long as the layout is based on Table1.  In your limited context, GoToLayout and GoToTable are pretty much the same thing...except that GoToTable doesn't exist.

               

              I find it typical that, when I create a record, the new record becomes the last record of the found set.  If I 'go to the next record'...nothing happens.


              mwtse wrote:

               

                If I forgot, then I will go into trouble. That is not a very good way to do program! 


               Step by step backups are wonderful things ;)  They take the pressure off of the "I forgot"s.

               

              • 4. Re: Create record in another table
                mwtse
                  


                If you are looping through records in table1 and want to go to the next record in table1, you should have focus on a layout based on table1 before you command to go to the next record. 

                 


                 

                 
                I wish I could. May be another design of the database structure can be used to avoid such switching of table. But I'm unable to figure out how to do that. I'm beginning to get a hang of FMP but lots have to be learnt. I have to change how I analysis the problem so that I could come up with a better way to implement the solution.
                 
                Thanks a lot for explaining. 
                • 5. Re: Create record in another table
                  philmodjunk
                    

                  To switch table context (really table occurrence context), simply do this:

                   

                  Freeze Window

                  Go to Layout[specify layout with the desired Table occurrence reference in layout setup...]

                  # do the stuff you need for this table here like creating a new record

                  Go to Layout[Original layout]

                   

                  This can be the entire script, or you can insert this into a larger script that performs other tasks.

                   

                  In the past, I have posted a suggestion to Filemaker's suggestion form that we have a "Set table context" "Release table context" pair of script steps so that we could do this without actually switching layouts (avoids issues with triggering script triggers and having to maintain hidden layouts strictly for such "context" purposes.)

                   

                  If you like this idea, you might want to do the same...

                  • 6. Re: Create record in another table
                    mwtse
                       Thanks a lot. That Freeze Window script really useful.