2 Replies Latest reply on Nov 17, 2011 4:09 PM by JoshuaKanuch

    Looping through Found Records

    JoshuaKanuch

      Title

      Looping through Found Records

      Post

      I am designing a database for a school. I am using FM Pro 11 and have heavily modified the "Registrations" starter solution. I have a table set up for Students, Classes, and Assignments. Students are "Registered" into classes via a script that adds records to a "Class Registration" table. They are also "Registered" into assignments via an "Assignments Registration" table. In my Assignments table, there is a field for "Assignment Class Name". The teacher creates an assignment by first selecting a class from a dropdown, then entering the assignment info.

      I want teachers to be able to create the assignment for an "Assignment Class", then click a button that finds all of the students that are in that class (from the "Class Registration Table") and creates new records for each student in the "Assignments Registration" table. I already have a script to assign an individual student an assignment, but I was wondering if it was possible to do it for all related records in that class.

        • 1. Re: Looping through Found Records
          philmodjunk

          Here's a generalized script outline that loops through a found set of record in a table named "Parent" to create one related record in a table named "child". You'll need to add a few details but the basic outline should be enough to enable you to set this up:

          #Perform a find, use Go to Related records, import records or whatever you need to do to get your set of parent records first
          #Script should be performed from Parent layout
          Go To record/request/page [first]
          Freeze window
          Loop
             Set Variable [$ID ; value: Parent::__pk_PrimaryKey ]
             Go to layout [Child]
             New Record/Request
             Set Field [Child::_fk_ForeignKey ; $ID ]
             Go To Layout [Parent]
             Go to Record/request/page [next ;exit after last]
          End Loop

          • 2. Re: Looping through Found Records
            JoshuaKanuch

            Thanks PhilModJunk, his was extremely helpful! Also thanks for the quick response, everything is working great.