In FileMaker everything happens "in context".
- Context
- Context is Everything
- David Attenbruh's World of FileMaker™ - Episode 1 - Context
- Best way to check FileMaker “Context”?
- Layout Context
In your case, everything happened in the context of the current record on the current layout. The first instruction did a lot less that you expected. It went to the first portal row but it remained in the current context. When you told it to make a new record that happened in the current context, not in the related table.
Your script needs to do this:
- Copy the current record ID into a variable
- Go to layout based on the related table
- Create a new record
- Use the value of the variable to set the foreign key to the establish the relationship
- Go back to the original layout
- refresh the portal
- go to field [ dépôt provisoire ]