Creating a new record in a linked table using code

S

I have 3 tables linked to create a many to many relationship.

The relationships look like this:   [Locations] <--- [Location Tracking] ---> [Tracking]

Multiple tracking records and be related to every location, and multiple locations can be related to every tracked record. I find the process of having to create a new record in Location Tracking from the Tracking table to be cumbersome, so would like to automatically create records in Location Tracking using code when certain Tracking activities are chosen. For example, if "Work" is chosen for Tracking, then "Office" would be automatically populated from the Locations table via the Locations Tracking table.

So far I have been able to create a new record in Location Tracking, but I'm not able to figure out how to link the "Work" Tracking record that has been created to the "Office" record in Locations.

Here is the code I've been playing with, which works to create a record but won't populate the Ids in Location Tracking.

let trackID := Id;
let locID := 6;
let newRec := (create 'Location Tracking');
newRec.Tracking.(Id := trackID);
newRec.Locations.(Id := locID)

Any suggestions?

Thanks,

Barry

A

You are almost there... Two things:

- use the "record()" function to create a record handle for the desired record in "Locations";

- set the reference field itself - not the ID of the referenced record - to the handle of the record you want to link.

let trackID := Id;
let newRec := (create 'Location Tracking');
newRec.(Tracking := trackID);
newRec.(Locations := record(Locations,6))

S

That's awesome! Thank you so much.

Reply