Samples::__pkSampleID = Tests::_fkSampleID
A portal to tests on a Samples layout might eliminate the need for a new layout, window and script as entering data directly in the portal can generate records in tests that are automatically linked to the current Samples record.
But you can also set it up this way:
In your script to open the new window, include a set variable step that holds the pk of your current samples record:
Set Variable [$$SampleID ; value: Samples::__pkSampleID ]
and so forth.
Then define _fkSampleID to include this auto-enter calculation:
and each new record that you create in your newly opened window for adding Tests records will automatically enter the value of this global variable and thus automatically link to the current record in Samples.
And it may be better to use OnRecordLoad on your Samples layout to capture the pk in the $$SampleID variable.