4 Replies Latest reply on Mar 20, 2014 2:13 PM by maurice2307

    create records from a script

    maurice2307

      Afternoon everyone,

       

      I’d like to ask for some pointers regarding the following.

       

      There are 2 variables, both dates. There is a table with a primary key, a date and a number.

      What are the correct script steps that creates a new record for each date between the variables (both variable dates included), and automatically enters the date in the appropriate field?

       

      Thank you.

        • 1. Re: create records from a script
          erolst

          Something along the lines of

           

          Loop

            New Record

            Set Field [ Table::date ; $dateBegin + $i ]

            Set Variable [ $i ; $i + 1 ]

            Exit Loop if [ $dateBegin + $i > $dateEnd ]

          End Loop

           

          where you should obviously perform some error checking beforehand, like $dateBegin not being empty and <= $dateEnd.

          • 2. Re: create records from a script
            wimdecorte

            first, make sure you are in the right context (use a Go To Layout if necessary)

             

            When you subtract the two dates you'll get a number. That's going to be your maximum number of iterations in your loop (need to add 1 if you want both dates included)

             

            set a counter variable to 0

            Now start a loop

            set a date variable to your start date + the counter

            create a new record

            set the date variable in the date field

            increment the counter

            exit the loop if the counter >= your max number

            end the loop

             

            you may have to tweak the "exit loop if" a bit to make sure the right number of records are created

            • 3. Re: create records from a script
              beverly

              Then, of course, if you're creating 'calendar' records - such as for scheduling - you may have a master list of dates that are holidays (to skip) and have the option to skip or include weekend days. But that gets a whole other set of testing inside the loop before the "create new record". 

               

              Beverly

              • 4. Re: create records from a script
                maurice2307

                Thank you Erolst, Wim and Beverly.