1 Reply Latest reply on Oct 26, 2011 9:36 AM by philmodjunk

    noob loop help



      noob loop help


      i have a table "event"  that contains "start date" and end date"


      there is a portal in the "event" layout to a table "schedule" that contains the field "date"


      in this portal, I want to automatically create a portal row for every date between event::start date and event::end date.


      my script reads


      Set schedule::date = event::start date

      If event::end date is not equal to end date


                go to next portal row 

                replace schedule date with schedule date +1

           end loop if schedule::date = event::end date

      end if

      It freezes filemaker every time and i am stumped.  Thank you in advance



        • 1. Re: noob loop help

          replace schedule date with schedule date +1

          is not an actual script step. What is the actual step? If you are using Replace Field Contents, then this is the wrong step and each time you run this script, that step might be attempting to modify 1000's of records in your table.

          Interacting directly with portals can be done with a script, but it's a bit of a "brittle" approach. Later changes to your layout can "break" your script. I recommend switching to a layout based on the portal's table, creating the new records there and then switching back to your original layout to display the results in your portal.

          Set Variable [$StartDate ; Value: Event::StartDate]
          Set Variable [$EndDate ; Value: Event::EndDate]
          Set Variable [$EventID ; Value: Event::EventID] //refer to primary key in Event table used to define portal's relationship
          Freeze Window
          Go To layout [Schedule ( Schedule) ] //assuming "Schedule" is name of related table shown in portal
            Exit Loop if [$StartDate > $EndDate ]
            New Record/Request
            Set Field [Schedule::Date ; $StartDate]
            Set Field [Schedule::EventID ; $EventID]
            Set Variable [$StartDate ; Value: $StartDate + 1]
          End Loop
          Go To Layout [Original Layout]

          Note: this script assumes original layout is based on Event with Event::EventID = Schedule::EventID as the portal's relationship. Be careful if you have any OnLayoutEnter or OnRecordLoad script triggers set on either of these two layouts as they might interfere with the correct execution of this script.

          Note: If you do decide to use a script to interact directly with a portal, you need first to enable "allow creation of records via this relationship" for teh portal's table in the relationship definition and then should use go to Portal row [last] to ensure that you are selecting the bottom "add" row of your portal. Set Field can then be used to enter a date and create the related record. Note also that if you have two or more portals on the same layout, you need to give the portal an object name and use got to object at the beginning of your script in order to set the focus on the correct portal.)