1 2 3 Previous Next 35 Replies Latest reply on Oct 31, 2016 10:30 AM by greatgrey

    Writing loop in script

    sam0723

      Hello everyone, i am new to filemaker. Recently, i am writing a script of copying data from other table.

      Here is part of my script

       

      loop

      set variable[$s1 ; Value: first name]

      set variable[$s2 ; Value: lastname]

      Go to record[next; exit after last]

      end loop

       

      Go to Layout

      new record

      set field

       

      so my question is how could i copy several records in the table A and copy this to table B?

        • 1. Re: Writing loop in script
          Johan Hedman

          Best thing is not to copy things from one table to another, better to have a relationship between the two tables.

           

          If you really need to copy data from one table to another here is how I would do it

           

          Go to record (first)

          Loop

               Go to layout (Table1)

               Set Variable ( $Field1 ; Value1)

               Set Variable ( $Field2 ; Value2)

               Go to layout (Table2)    

               Create new record

               Set Field ( Field1 ; $Field1)

               Set Field ( Field2 ; $Field2)   

               Go to layout (Table1)

               Go to record (next, finish after last)

          End Loop

           

          Read free FileMaker Training Series to learn more about FileMaker

          FileMaker Training Series | FileMaker

          • 2. Re: Writing loop in script
            sam0723

            Thank you Johan. I agree with you. the user would like to transfer the data of sibling to a new student so that they don't require to enter the data of his/her family again. Is there any better method i could use instead of writing a script to copy the data?

             

            i am using filemaker 14

            • 3. Re: Writing loop in script
              philmodjunk

              Use two tables in a relationship. Put data that will be the same for all siblings in a Family table with one record per table. Put data unique to each sibling in a related table with one record for each family member. Link the two tables by family ID.

              • 4. Re: Writing loop in script
                sam0723

                Thank you philmodjunk, if the family have more than one sibling, than two siblings for example will have same id, is that ok for database management?

                • 5. Re: Writing loop in script
                  philmodjunk

                  They would have the same FamilyID to link to the same record in the Familly table. They should also have another field with a unique ID that identifies each sibling uniquely.

                  • 6. Re: Writing loop in script
                    sam0723

                    You mean i create a join table linking up student, parent and sibling?

                    • 7. Re: Writing loop in script
                      philmodjunk

                      No, you link the sibling records to the Family table by a FamilyID field that identifies the family. THen another field, SiblingID or some such name would identify each individual sibling.

                       

                      You would only need a join table if you need to show that a sibling is a member of more than one family. That might be necessary given divorce/remarriage etc. But it isn't needed for what we have discussed to this point.

                      • 8. Re: Writing loop in script
                        sam0723

                        Thank you. The users would like to see family member of the student so i should create a family table linking student and also sibling table?

                        • 9. Re: Writing loop in script
                          philmodjunk

                          Student and sibling would be the same table as far as I can tell from here.

                          • 10. Re: Writing loop in script
                            sam0723

                            You mean i don't need to create a sibling table? just create a student and family table? and using family id to link up two tables? how could i transfer the data of sibling as a new student?

                            • 11. Re: Writing loop in script
                              philmodjunk

                              Keep in mind that i have almost no idea what exactly you are trying to do, but yes each student from the same family would link to the same family record. The idea here is that you would not copy any information from one student record to another. If the information is common to the family, and thus the same for each student, you put that information in the family record. Then, since both students of the same family link to the same family record, this info can be displayed for both students and does not have to be copied nor entered a second time.

                              • 12. Re: Writing loop in script
                                sam0723

                                Thank you. Actually, i am trying to create a student database to store the information of the student. There is a possibility for their sibling to change to student so i need to find a way to store the whole family information and also able to change the sibling as a new student. so the family information is not required to enter again and the relationship of the whole family could be shown in the layout.  Is that clear to all of you?

                                • 13. Re: Writing loop in script
                                  philmodjunk

                                  The change from sibling to student might be just changing the value of a field that has a different value for siblings that are enrolled.

                                  • 14. Re: Writing loop in script
                                    sam0723

                                    Thank you, changing the value of a field? you mean the id field?

                                     

                                    so i need to create a student table and a family table.

                                     

                                    For the student table, i should create a id field and family foreign key field and link up to family table.

                                     

                                    For the family table, it will store the information of parents and sibling with the family id.

                                     

                                    Is that right?

                                    1 2 3 Previous Next