I wrote a script to create a new record in a related table and populate some of the fields. One of the fields is being populated by a variable that is saved from a global field before switching to the related table, and at the end of the script, I want to clear this global field. Here's what I have written: (starts from Teams table)
Commit Records/Requests
Set Variable [ $TeamsID; Value:Teams::TeamID ]
Set Variable [ $ProgramID; Value:Teams::gAllPrograms ]
Go to Layout [ “MembershipPivot” (MembershipPivot) ]
New Record/Request
Set Field [ MembershipPivot::TeamID; $TeamsID ]
Set Field [ MembershipPivot::ProgramID; $ProgramID ]
Go to Layout [ “Teams” (Teams) ]
Clear [ Teams::gAllPrograms ]
For some reason, the script creates the record I want, then clears the global gAllPrograms field and then tried to make another record in MembershipPivot! I can't figure out what is going on. Seems like it's looping but there are no loops in the script. Also, if I take out the last command, Clear [ Teams::gAllPrograms ], it only creates the one record I want and does not loop. Any ideas?
Ok, I forgot to mention that I was triggering the script using the DoScript plugin...and that seems to be where the problem is. If I trigger it instead from a button, it works fine. However, if I change the gAllPrograms field to an auto-fill with this calculation:
Let ( queueScript = mFMb_DoScript ( "CreateMembershipRecordFromTeams" ) ; gAllPrograms )
the script loops. Clearly I do not understand how this plugin works...any idea how to still trigger the script after gAllPrograms field selection, but avoid the looping issue?