Are scripts stacked for execution or is it possible that a second script fires (e.g. by a key Cmd-N) before another script is finished?
Hard to test with debugger on but it may explain some erratic behaviour.
User is on record 1 (is committed, not transactional) and starts a complex looping script to create ca. 5 child records but before the results are completely processed the user hits Ctrl-N, hooked up to a generic script in another UI-file to start a new record in any layout the user is currently active.
The new record (2) is indeed created, the child records for record 1 are created (with the correct foreign key for 1, but the original record 1 is no longer there. There are no triggers OnRecordLoad etc. on this layout.
Is it possible that the script for new record fires before the other script is finished or are they stacked?