3 Replies Latest reply on Oct 16, 2013 7:23 AM by philmodjunk

    random dates for employees

    jakedanible

      Title

      random dates for employees

      Post

           I an trying to set up a database for employee testing and I need to generate random dates each month for each employee.  Some employees could need 1 to 10 random dates per-month.  would be nice to have a field so you could pick the number of random dates needed for that employee and have them show on a calendar.  Any help or ideas on how best to create this would be helpful.

           Thank you

           Jake

        • 1. Re: random dates for employees
          philmodjunk

               There are a number of calendar demos. SeedCode has one and I have this very simple calendar demo file: https://www.dropbox.com/s/e8d03xvwe8vtz85/Calendar.fp7

               If you set up a field into which you can enter or select the desired number of dates, you could use code such as I've put in the following example. The example script creates random dates for the current month, but it can easily be adapted to work with any month you specify.

               Set Variable [$DaysInMonth ; value: Let ( T = Get ( CurrentMonth ) ; Date ( Month ( T ) + 1 ; 0 ; Year ( T ) ) ) ]
               Loop
                   Exit Loop If [ $K > YourTable::NumberOfDatesField ]
                   Set Variable [$RandDate ; Date ( Month ( Get ( CurrentDate ) ) ; Int ( Random * $DaysInMonth ) + 1 ; year ( get ( CurrentDate ) ) ) ]
                   If [ IsEmpty ( FilterValues ( $DateList ; $RandDate ) ) // new random date ]
                      Set Variable [ $DateList ; value: List ( $DateList ; $RandDate ) ]
                      Set Variable [$K ; value: $K + 1 ]
                   End If
               End Loop

               This creates a list of random dates separated by returns. Your script can then loop through them created one record in table used by your calendar layout for each date in the list, also with the employee's ID so that you can link the date to an employee.

          • 2. Re: random dates for employees
            jakedanible

                 thanks for your help. 

                 I am new to file maker as you can tell. Sounds like I need to learn a lot more about scripts.  any suggestion as to what the best training via the web would be? 

                 also when you said create a loop to create a record in the calendar table would that loop be added to the example script you posted or would it be a new script to run after the 1st script?

            • 3. Re: random dates for employees
              philmodjunk

                   "best training" will be different for each individual. Each person starts with a different basic skill set and a unique set of skills/challenges for learning new information. You'll need to research and evaluate your options.

                   

                        when you said create a loop to create a record in the calendar table would that loop be added to the example script you posted or would it be a new script to run after the 1st script?

                   Either option produces exactly the same result so long as the second script can access the list produced by the first. If you use separate scripts, you would need to use a) a global variable ($$); b) a field, or c) pass the list as a script parameter to make that list available to a second script.

                   Thus, adding that scripting to the end of my example script will be simpler.