Think of variables as "buckets". Your script can load one or more "buckets" with data from your current record on your current layout and then can change to a different layout, create a new records and dump the data from the buckets into corresponding fields in the newly created record.
The basic code looks something like this:
Set Variable [$ID ; YourTable::PrimaryKey ]
go to Layout [RelatedTableLayout]
Set Field [YourRelatedTable::ForeignKey ; $ID]
Go to Layout [original layout]
You can use as many pairs of set variable/set field as you need for moving data from the first table to a new record in the second, but once you have created a new record and set the foreign key field, you may also have established a relationship link back to the current record of the original table, so you often do not need to use more variables.