no, you re not quite getting it.
when the record is inserted, a session is created that contains the primary key value of the record. This is done inside of the insert record behavior. You wont need to move any code around. You dont need to be concerned about the order of the code that is creating the session variable except to make sure that the record is inserted to the parent table before inserting to the child table.
on the insert that goes into the child table, use the session variable form the parent table insert in the foreign key column.
no, you do not need to set up foreign key column in the database.