New Record missing data

What am I missing???  In FM8, I have 2 related tables in a single database.  I create a new record in the primary table and want to create an empty record in the related table but do want to insert the appropriate data in the field that is used to relate the two.  Of course I only want to create a new record in the related table if none exists.  My script is:

// I am in a layout for table "personal".  I commit the record I am entering.

Commit Records/Requests [ Skip data entry validation; No dialog ]

// Now I want to check to see if a related record exists, and if not create one.

Set Error Capture [On]
Go to Related Record [ From table: “Research”; Using layout: “ResearchTable” (Research) ][ Show only related records ]
If [ Get(LastError) <> 0 ]
   Go to Layout [ “ResearchTable” (Research) ]
   New Record/Request

// Here's where the problem arises.  A new blank record is created, but the personid field is never updated
// by the next statement.  I tried adding a go to field script step but that made no difference.

   Set Field [ Research::PersonID; Personal::PersonID ]
   Commit Records/Requests [ Skip data entry validation; No dialog ]
End If

I'm sure this is something trivial, but I can't figure it out.  Thanks for any help.
dspaceAsked:
Who is Participating?
 
lesouefCommented:
Can't work: at the very moment where you set Research::PersonID, the relation does not exist yet, since research::PersonID is still empty, so you define this in the current record, god knows which one that is!

There are several ways to do this, the easiest for me is:

Set Error Capture [On]
Go to Related Record [ From table: “Research”; Using layout: “ResearchTable” (Research) ][ Show only related records ]
If [ Get(LastError) <> 0 ]
set variable $id = Personal::PersonID           <<<<<<<<<<<<< add on
   Go to Layout [ “ResearchTable” (Research) ]
   New Record/Request

// Here's where the problem arises.  A new blank record is created, but the personid field is never updated
// by the next statement.  I tried adding a go to field script step but that made no difference.

   Set Field [ Research::PersonID; $id ]  <<<<<<<<<<<<<<< modification
   Commit Records/Requests [ Skip data entry validation; No dialog ]
End If
0
 
dspaceAuthor Commented:
Worked like a charm.  Thanks for your help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.