Script to add records to related table
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)
- Date (type Date) - '7/10/2012'
- Program (type Text) - 'Beethoven's Ninth'
- Line (type Text) - example: '652'
- Lot (type Text) - 'Westwood'
- DefaultAgency (type Text) - 'Tour Coach'
- 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
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]
What works - it creates new schedule lines with the correct date
What doesn't work:
- it goes into an infinite loop
- Only a '?' mark shows for the Line field
- No value shows for the Agency field
Can anyone give me some suggestions?