I think there is a confusion....
You have 2 tables : Parent and Child.
You have a relationship:
If you set the $variable to the Parent::PrimaryKey then go to the ChildLayout and create a new record and set the Child::ForeignKey to the value of $variable then you have created the relationship.
WHat I want to know is where you have used a portal at all?
BTW: You could have done this in the ParentLayout by simply entering data for name DOB etc in a Portal for ChildTable ON THAT LAYOUT. This would require the options on the relationship to allow records to be created via this relationship.
There are some excellent resources for you to read about relationships. Look in the Technical Resource Centre Tab.
Your variable $Scan seems to be set correctly as you have written it. Is there a problem with your script? Is the new record not being created in Child?
If it's not being created, this may be a permissions issue of the user not having permission to create Child records. Or the layout may be set to not allow editing. Of the Child's foreignKey field may not be editable or may be set to validate as unique or some other issue.
Is the script acting on a pre-existing Child record rather than creating a new record before setting the fKey? This may indicate a loop to test for a new record with a blank fKey is needed before executing the SetField.
You might benefit from a Commit Record step after the SetField.
The script as you have written it looks like it should work, assuming all the other file and field settings don't conflict with what it's trying to do. Let us know what the problem is.
Go to Layout (original layout)
at the end of the cript will make the whole procces invisisble to the user.