Creating a relationship using a global variable in FM10:

  1. create the relationship in the graph of FM (i.e. person: person_pk to history: person_fk)
  2. from inside a script, if you need to view the relationship:
    Set Variable [$$person_id; Value:person::pk_person_id]
    If [IsValid(person_pk2fk_history::fk_person_id]
    Go to Related Record [Show only related records; From table: "person_pk2fk_history" Using layout: "history_edit" (person_pk2fk_history)
  3. from inside a script, if you need to create a new record as no relation exists yet:
    Go to Layout ["history_edit"(person_pk2fk_history)
    New Record/Request
    Set Field[person_pk2fk_history::fk_person_id; $$person_id]
    Commit Records/Requests[No dialog]

Some remarks:

$$person_id is a global variable set when it is first called.

At point 2, we first set a global var ‘person_id‘ and set the value to the pk_person_id field in person. Then we make a check whether the relational table (i.e. history) has already been created or not. If this is valid, we call the procedure ‘Go to related record‘ and show the related records only.

At point 3, we create a new record after checking that no relational record exists (this is done at step 2 and step 3 is called if relation does not exist). Then we call the New record command and finally the Commit to save the newly added record and start entering data.