3 Replies Latest reply on Oct 22, 2012 3:44 AM by jbrown

    Creating Multiple Records, skipping days

    jbrown

      Hi all,

      I've got a function that needs to happen:

      Teachers are able to assign after school "Office Hours" to students for various reasons. They want to be able to go to that student's record and pick days of the week on which to assign the office hours. They could choose any week day. They also need to pick how many days they want office hours and the start date.

       

      I've got a layout that shows the days of the week as Checkbox Booleans, one for each day. The layout also contains the number of days and the start date fields.

       

      What i need to be able to do is create records in the Office Hours table for those days only that they chose, starting on the day they chose, and for the number of days they chose.

       

      I actually did this in the past, but the script was long and cumbersome. I feel like there's a better way.

       

      What I'm thinking is i loop through the part of the script that creates the records for the number of days that they chose in the global field described above.

       

      The issue that I have is with the date field being set to the right date, depending on the booleans that were checked off on the layout. For example, if i chose to M and W for 5 days, I should get records with the date of 10/22, 10/24, 10/29, 10/31, and 11/5. How do I do this in an efficent manner?

       

      Thanks

        • 1. Re: Creating Multiple Records, skipping days

          Hi Jeremy,

           

          gNumTimes, gChecklist and gDateStart should be global fields.  I was not clear on the values in your value list.  It sounded like you've created one for each day of week.  Anyway, this is based upon checklist with only 2, 3, 4, 5, 6 in the custom vl. Then script might look like this (assuming fired on Student layout):

           

          CREATE STUDENT CLASSES

           

          #  test for empty criteria

          If [ not Students::gDateStart or not Students::gNumTimes or IsEmpty ( Students::gChecklist ) ]

          Show Custom Dialog [ Message: "Requires Start Date, Number of Records, and Day of Weeks"; Buttons: “OK” ]

          Halt Script

          End If

          #

          Set Variable [ $studentID; Value:Students::StudentID ]

          Freeze Window

          Go to Layout [ “Classes” (Classes) ]

          Loop

          #  loop through the dates to set

          Exit Loop If [ $days ≥ Students::gNumTimes ]

          If [ Let ( $i = $i + 1 ; not IsEmpty ( FilterValues (  DayOfWeek ( Students::gDateStart + $i ) ; Students::gChecklist ) ) ) ]

          New Record/Request

          Set Field [ Classes::StudentiD; $studentID ]

          Set Field [ Classes::ClassDate; Let ( $days = $days + 1 ; Students::gDateStart + $i ) ]

          End If

          End Loop

          #  It is not clear where you would like to end up.  If back on Students, include a Go To Layout [ original ] here

           

          ... and if you need assistance with adjusting it to your value list, let us know.  :^)

          • 2. Re: Creating Multiple Records, skipping days

            Also it was not clear what to do if the start date WAS one of the checked days.  As is, it would NOT evaluate the current date and only begin evaluating on the next day. 

            We can adjust this as well.

            • 3. Re: Creating Multiple Records, skipping days
              jbrown

              Thanks for the information and script.

              I figured out how this works: I changed the value list to include days of the week and used the DayName() function to do the filtering, but the script works perfectly. It quickly assigns the correct days.

              Thanks a lot.