6 Replies Latest reply on Dec 10, 2011 6:14 PM by filemaker72

    Generating Attendance Form - Loop exits early

    ReynaldoRamirez

      Title

      Generating Attendance Form - Loop exits early

      Post

      I am trying to create student attendance records so that I may mark each student Present, Excused Absence, Unexcused Absence.

       

      I am using three databases in this scenario/

      Student Information

      Student Attendance

      Class Dates

       

      Here are the relationships.

      Student Information::SSID>--------=-----------<Student Attendance::SSID  (These relate to their student ID)

      Students Attendance::Date>--------=-----------<Class Dates::Date

       

      I am using one master script that is calling on two subscripts.  The problem is that the loop portion of the script randomly exits early and doesn't generate a new record for all the students in the found set.  It gets about a third to half of the way.  Also, something to note...when I get to the Get SSID portion...after I enter the date and the first script is paused...I get this "command-period" symbol.  I have to press "command-period" before it actually runs the second script.

       

      Here is the master script: Attendance Form

      Perform Script [ “Attendance: New Record with Same Date” ]

      Loop

        Perform Script [ “Get SSID” ]

      End Loop 


      Subscripts:

      Attendance: New Record with Same Date

      #Creates 1st record for the new date and first student record

      Go to Layout [ “Student Record” (Student Information) ]

      Perform Script [ “Filter Enrolled” ] (#Creates a found set for enrolled students)

      Go to Record/Request/Page [ First ]

      Set Variable [ $id; Value:Student Information::SSID ]

      Go to Layout [ “Attendance” (Student Attendance) ]

      New Record/Request

      Set Field [ Student Attendance::SSID; $id ]

      Pause/Resume Script [ Indefinitely ] 


      Get SSID

      #Creates new student records inputing SSID and the Date

      Set Variable [ $date; Value:Student Attendance::Date ]

      Go to Layout [ “Student Record” (Student Information) ]

      Go to Record/Request/Page [ Next; Exit after last ]

      Set Variable [ $id; Value:Student Information::SSID ]

      Go to Layout [ “Attendance” (Student Attendance) ]

      New Record/Request

      Set Field [ Student Attendance::SSID; $id ]

      Set Field [ Student Attendance::Date; $date ] 


      -----

       

      What am I doing wrong here?  When I run the "Get SSID" script manually...it does stop after I get to the last student, but it won't do it when I put it in a loop.

      Thanks for your help!

       

        • 1. Re: Generating Attendance Form - Loop exits early
          philmodjunk

          Perform Script[ “Attendance: New Record with Same Date” ]

          Loop

            Perform Script[ “Get SSID” ]

          End Loop

          You need an exit condition for this loop or your script will call Perform Script endlessly. This could explain the command period symbol that you are seeing as this appear automatically  when a script is running, it's just that most scripts complete so quickly that you don't see them.

          Seems like your script should follow this general out line:

           

          Perform Script [ “Attendance: New Record with Same Date” ]
          Go to Layout [ “Student Record” (Student Information) ]
          Go To Record/Request/Page [Next]
          Loop
            Perform Script
          [ “Get SSID” ]
            Go to Layout [ “Student Record” (Student Information) ]
            Go To Record/Request/Page [next ; exit after last]
          End Loop

          • 2. Re: Generating Attendance Form - Loop exits early
            ReynaldoRamirez

            That pointed me in the right direction!

             

            I just had to remove the underlined sections in Get SSID and move the set variable for $id down....otherwise it only showed half of my students (every other one)

             

            Get SSID

            #Creates new student records inputing SSID and the Date

             

            Go to Layout [ “Student Record” (Student Information) ]

            Go to Record/Request/Page [ Next; Exit after last ]

            Set Variable [ $id; Value:Student Information::SSID ]

            Go to Layout [ “Attendance” (Student Attendance) ]

            Set Variable [ $date; Value:Student Attendance::Date ]

            New Record/Request

            Set Field [ Student Attendance::SSID; $id ]

            Set Field [ Student Attendance::Date; $date ] 

             
            So to recap...the problem was that I didn't create an exit condition for the script.  The final script looks like this:
             
            Master Script: Attendance Form
             
            Perform Script [ “Attendance: New Record with Same Date” ]
            Go to Layout [ “Student Record” (Student Information) ]
            Go To Record/Request/Page [Next]
            Loop
              Perform Script
             [ “Get SSID” ]
              Go to Layout [ “Student Record” (Student Information) ]
              Go To Record/Request/Page [next ; exit after last]
            End Loop

            Subscripts:

            Attendance: New Record with Same Date

            #Creates 1st record for the new date and first student record

            Go to Layout [ “Student Record” (Student Information) ]

            Perform Script [ “Filter Enrolled” ] (#Creates a found set for enrolled students)

            Go to Record/Request/Page [ First ]

            Set Variable [ $id; Value:Student Information::SSID ]

            Go to Layout [ “Attendance” (Student Attendance) ]

            New Record/Request

            Set Field [ Student Attendance::SSID; $id ]

            Pause/Resume Script [ Indefinitely ] 


            Get SSID

            Set Variable [ $id; Value:Student Information::SSID ]

            Go to Layout [ “Attendance” (Student Attendance) ]

            Set Variable [ $date; Value:Student Attendance::Date ]

            New Record/Request

            Set Field [ Student Attendance::SSID; $id ]

            Set Field [ Student Attendance::Date; $date ] 


            THANK YOU!


            • 3. Re: Generating Attendance Form - Loop exits early
              filemaker72

              Hi Reynaldo,

              I was wondering if you could help me out. I'm new to FM and I've been trying to solve a very similar problem - Creating an attendance sheet form for a filtered set of records. 

              I created a practice FM file to see if i could get your script to work.

              I created the same tables as you have: Student Information, Student Attendance, Class Dates.

              For fields:

              Student Information - SSID (as the primary key), Student Name, Class Day, Class Block (sorting info)

              Student Attendance - SSID (as foreign key), Attendance Status, Dates, (Student Information::Student Name (to check the results after the script))

              Class Dates - _kp_class_dates, Dates

              In Student Information, I created 10 students. In Class Dates, I created a separate record for each date (1/30/2011-2/3/2012)

              I connected them as follows: Student Information: SSID ----< Student Attendance: SSID (one to many), Student Attendance: Date >-----< Class Dates: Dates (many to many). I uploaded an image. It has: 1) The relationship chart 2) The results of the Attendance table after I ran the script (a new record with a student in each) 3) Each of the tables.  

              After running the script, it created a new record in the Attendance table for all the students, but there were no dates inputted.

              The script "Attendance: New Record with Same Date" makes sense to me as far as creating new records, but I'm not sure how the dates are being inputted. From looking at the script, it would seem to me that the dates would be blank because in Get SSID, Set Variable [$date; Value: Student Attendance::Date] isn't that 'blank' to start with? I'm sure I'm missing something..

              - Did I create the relationships correctly?

              - Where do those dates come from?

              I'd appreciate any kind of help you could give me.

              • 4. Re: Generating Attendance Form - Loop exits early
                filemaker72

                One follow up:

                When I initially run the script, it pauses after the first record is made in Attendance. (in this case, SSID 1, Bri)

                So this time, I entered a date after the first record was made: 1/31/2012.

                After that, the script worked and filled in the rest of the dates for the rest of the students.

                So... I can do that, but I was wondering is that how you intended the script to run? Also, if that's the case, what's the Class Dates table for?

                 

                Oh and I made an error: the dates are 1/31/2012 - 2/3/2012 (as shown in the image).

                 

                Thanks again. I'd love to hear from you if you have time.

                • 5. Re: Generating Attendance Form - Loop exits early
                  ReynaldoRamirez

                  Yes.  That is what I intended.  I have the class dates table, so that I can view all the students, through a portal, and easily change their status from present to absent.  (I have since set it up to have "Present" be automatically selected and then I go through and mark the unexcused or excused absences.

                  Hope it works for you.

                  • 6. Re: Generating Attendance Form - Loop exits early
                    filemaker72

                    Thanks.. and thanks for the screenshot. I have a better idea how to use the script now.