Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 341
  • Last Modified:

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.
0
dspace
Asked:
dspace
1 Solution
 
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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now