0 Replies Latest reply on Apr 12, 2013 12:03 PM by jmatchan@laphil.org

    Script to add records to related table

    jmatchan@laphil.org

      Title

      Script to add records to related table

      Post

           Sorry for the question, but I'm new to FM.  I've searched the forums and thought I had an answer, but it's not working the way I thought it would.

           I'm creating an app that tracks the shuttle buses scheduled for event.  Here are the main table (so far)

            

           table: events

             
      •           Date (type Date) - '7/10/2012'
      •      
      •           Program (type Text) - 'Beethoven's Ninth'

            

           table: bus_lines

             
      •           Line (type Text) - example: '652'
      •      
      •           Lot (type Text) - 'Westwood'
      •      
      •           DefaultAgency (type Text) - 'Tour Coach'

            

           table: schedule

             
      •           Date (type Date) - related to 'Date' in table 'events'
      •      
      •           Line (type Text) - related to 'Line' in table 'bus_lines'
      •      
      •           Agency (type Text) - defaults to 'Default Agency' in table 'bus_lines' but can be changed via lookup value
      •      
      •           InboundBuses (type Number) - entered manually by user
      •      
      •           InbountTrips (type Number) - entered manually by user
      •      
      •           OutboundTrips (type Number) - entered manually by user

            

           I've used a portal setup to display the related schedule on the Events layout.  There are 15 standard bus lines that need to be created for each new event entered into the database.  

            

           I've made a script "create schedule" with the following steps

           Set Variable [$counter; Value:1]
           Go to Layout ["Scheduled Buses" (schedule)]  #passes a parameter for event date
           Loop
           New Record/Request
           Set Field [schedule::Date; Get (ScriptParameter)]
           Set Field [schedule::Line; GetNthRecord (bus_lines::Line; $counter )]
           Set Field [schedule::Agency; lines::DefaultAgency]
           Set Variable [$counter; Value:$counter+1]
      Exit Loop If [$counter > bus_lines::Count]
           End Loop

            

           What works - it creates new schedule lines with the correct date

           What doesn't work:

             
      1.           it goes into an infinite loop
      2.      
      3.           Only a '?' mark shows for the Line field
      4.      
      5.           No value shows for the Agency field

           Can anyone give me some suggestions?