The script that runs when you press a button should do the following:
1. Grab the ID from the account record you're on in a variable. I use $ID as the variable
2. Go to a layout of the child table
3. Create a new record
4. Set the foreign key field to the value in the $ID field
5. Set the other fields to the globals.
5.5 Commit the record.
6. Go back to the layout you were originally on.
7. Clear the globals.
If the first child record is being modified with the data from the 2nd try, that makes me think you're not either creating a new record or you are modifying the values in the portal. Without specific direction, the script will set the fields in the first row of the portal.
I never use a portal to set fields. I always use the method described above to create related records.
Thank you. Can you explain variables please?
A variable is simply a piece of memory that holds a value. Its a typical technique of FileMaker developers to store data into variables and use it elsewhere.
Check out the demo file I have here. This demos what you're trying to build. I use a variable called $ID to hold the primary key so that I can use it to create a new record in the child table.
And, if you havent done so, I recommend you read the FileMaker Training Series. It talks about variables and how to use them throughout your system.
CreateNewRecords.fmp12.zip 70.0 K