Adding child records to a 1:M linked form

Tap Forms – Organizer Database App for Mac, iPhone, and iPad Forums Script Talk Adding child records to a 1:M linked form

Viewing 3 reply threads
  • Author
    Posts
  • December 24, 2020 at 6:50 PM #42968

    Paul Wirth
    Participant

    I’m importing some records of clients via csv. One column in the csv contains multiple appointment dates per client.

    I want the clients to go into my Clients form. The Clients form has a Link to Form field called Appointments. It’s a 1:M field and “Show Inverse Relationship” is checked.

    I need the clients to be imported as records in the Clients form, and the multiple dates per client from the csv to be entered as child records in the Appointments form.

    I don’t think there’s a way to do that all in import, so I figured I’d:
    1. Import the csv into Clients, while creating a new field “Dates to Process” to capture the multiple appointment dates
    2. Use a script to loop through “Dates to Process” and create the appropriate records in Appointments

    For step 2, I’m pretty sure I can loop through the “Dates to Process”, but I don’t know how to apply each date as a new record in “Appointments” that’s associated with that client in the parent Clients form. I see that in the script editor, I can tap on one-to-many icon next to Appointments, and get its ID, but after that, I’m at a loss.

    Any help would be appreciated!

    December 24, 2020 at 8:17 PM #42972

    Brendan
    Keymaster

    Hi Paul,

    You can use the var newRecord = record.addNewRecordToField(field_id); function to add a new record to a Link to Form field (or a Table field).

    You’ll get a record object back which you can then set your values on.

    Then save the form and everything will be saved.

    December 24, 2020 at 8:19 PM #42973

    Brendan
    Keymaster

    Oh, and just to clarify, in the above example, the field_id would be the ID of your Link to Form field and record is the parent record. newRecord is the child record.

    December 25, 2020 at 4:58 PM #42993

    Paul Wirth
    Participant

    Worked like a charm. Thanks, Brendan!

Viewing 3 reply threads

You must be logged in to reply to this topic.