8 Replies Latest reply on Jun 4, 2016 3:39 PM by xfiring

    Auto create dates & times of classes

    xfiring

      What I am trying to figure out is how to auto create events/dates based upon start/end dates and classes that run during a period.  The example here is an exercise class that would be like this:

       

      Class term beings: June 3, 2016 and ends August 3, 2016 and 'class 1' meets on Monday's at 5:00pm, Wednesday at 6:00pm, and Saturday at 9:00am every week from the start of the class till the end of the class session.


      What I am looking to do is automatically create the entries for these days.  So basically if I could just create the class, select the times and it would automatically create these times (or whatever the times may be) from the start date till the end date.   I am pretty new to FileMaker but I figure if I could figure out how to get this working, I could then link these results to an actual calendar module to be displayed and attendance tracking.

       

      I hope thIs makes sense and if I could get some guidance on where to start that would be great.

       

      Thanks

        • 1. Re: Auto create dates & times of classes
          erolst

          Assuming you have a table Class with start and end date, and another table ClassDay …

           

          Set Variable [ $classID ; Class::id ]

          Set Variable [ $dateCheck ; Class::dateBegin ]

          Set Variable [ $dateEnd ; Class::dateEnd ]

          Set Variable [ $theDays ; "2¶4¶7" ]

          Set Variable [ $theTimes ; List ( " " ; Time ( 17 ; 0 ; 0 ) ; " " ; Time ( 18 ; 0 ; 0 ) ; " " ; " " ; Time ( 9 ; 0 ; 0 ) ) ]

          Go to Layout [ ClassDay ( ClassDay ) ]

          Loop

          Set Variable [ $dow ; DayOfWeek ( $dateCheck ) ]

            If [ dow = 2 or dow = 4 or dow = 7 ]

              New Record

              Set Field [ ClassDay::id_class ; $classID ]

              Set Field [ ClassDay::theDate ; $checkDate )

              Set Field [ ClassDay::theTime ; GetValue ( $theTimes ; dow ) ]

            End If

            Exit Loop If [ Let ( $dateCheck = $dateCheck + 1 ; $dateCheck > $dateEnd ) ]

          End Loop

          • 2. Re: Auto create dates & times of classes
            xfiring

            Thanks.  How would this work if I wanted to modify the dates because each class would have different days and could have any combination?  So basically class 2 could be Monday 3:00pm, Tuesday 12:00pm, etc.  Basically the variables would somehow need to be set so that whatever days and times are selected it just creates based on the input days of the weeks and times, if that makes sense.

             

            Thanks so much for the quick response, I will need to work through this a little bit!

            • 3. Re: Auto create dates & times of classes
              erolst

              xfiring wrote:

              How would this work if I wanted to modify the dates because each class would have different days and could have any combination? So basically class 2 could be Monday 3:00pm, Tuesday 12:00pm, etc. Basically the variables would somehow need to be set so that whatever days and times are selected it just creates based on the input days of the weeks and times, if that makes sense.

               

              You can either change the hardcoded values in the script, or – which would be more more convenient, because then you can specify the data in the UI and generalize the script – use a repeating time field with 7 repetitions; store the time of day in the repetitions that corresponds with the weekday number of the day (where 2 = Monday, 3 = Tuesday etc.).

               

              If you display two copies of the field with reps 2-7 and 1 ( underneath), respectively, this is the common Monday to Sunday sequence:

               

              Screen Shot 2016-06-04 at 17.31.24.png

               

              So assuming you have this field Class::times[7], try

               

              Set Variable [ $classID ; Class::id ]

              Set Variable [ $dateCheck ; Class::dateBegin ]

              Set Variable [ $dateEnd ; Class::dateEnd ]

              Loop

                Exit Loop If [ Let ( [ $i = $i + 1 ; $thisRep = Class::times[$i] ] ; $i > 7 ) ]

                Set Variable [ $theTimes ; List ( $theTimes ; Case ( $thisRep ; $thisRep ; " " ) ) ]

                Set Variable [ $theDays ; List ( $theDays ; Case ( $thisRep ; $i ) ) ]

              End Loop

              Go to Layout [ ClassDay ( ClassDay ) ]

              Loop

                If [ not IsEmpty ( FilterValues ( $theDays ; DayOfWeek ( $dateCheck ) ) ) ]

                  New Record

                  Set Field [ ClassDay::id_class ; $classID ]

                  Set Field [ ClassDay::theDate ; $checkDate )

                  Set Field [ ClassDay::theTime ; GetValue ( $theTimes ; dow ) ]

                End If

                Exit Loop If [ Let ( $dateCheck = $dateCheck + 1 ; $dateCheck > $dateEnd ) ]

              End Loop

              • 4. Re: Auto create dates & times of classes
                xfiring

                This looks exactly right. I think I am in a little bit over my head here as I am starting out.  Any chance you could put this in a sample easy demo file I could look at how this works?  I can put this together but I am not sure if I need 7 date fields, or one date field with the days of the week in it (Date field 1, Date field 2, Date filed 3, etc?  (E.g. Class::[7] I am not sure what this means for example]

                 

                I am honestly very grarefuel at how nice you've been putting this together thus far and am encouraged by how generous the FileMaker community looks. 

                • 5. Re: Auto create dates & times of classes
                  erolst

                  Kind of you to say that.

                   

                  See if the the attached file helps you.

                  • 6. Re: Auto create dates & times of classes
                    xfiring

                    No problem at all, this is above and beyond!

                     

                    So when I opened the file and go to Class layout, and put the begin/end dates and then class times in, I am not sure what to do next?  In layout mode I can see there is a create class days script and other fields at the top that appear they should populate the classes with the dates and times, however, they are hidden in browse mode.

                     

                    Also, I am not sure what the very bottom field 'class day created' is doing.

                     

                    However, these questions aside, this is exactly what I was looking for!  Thank you so much for you time!

                    • 7. Re: Auto create dates & times of classes
                      erolst

                      xfiring wrote:

                       

                      In layout mode I can see there is a create class days script and other fields at the top that appear they should populate the classes with the dates and times, however, they are hidden in browse mode.

                       

                      Also, I am not sure what the very bottom field 'class day created' is doing.

                      The only thing hidden is the button ... delete the 1 from classDayCreated - this is a flag to indicate that the records have been created. If set, it shows the portal and hides the button (and vice versa if empty).

                       

                      Also, simply create a new class record, fill in the fields and click the button ...

                      1 of 1 people found this helpful
                      • 8. Re: Auto create dates & times of classes
                        xfiring

                        Thanks again!