Copying from related record

Viewing 1 reply thread
  • Author
    Posts
  • October 30, 2019 at 1:56 PM #37581

    Simon Inchley
    Participant

    I want to put into a field a value from a field in a related record. I’ve defined the relationship as a “join”, based on a different field in each form, and for present purposes it doesn’t matter to me which of the forms is the parent and which the chid. I’ve written a really basic script, where the target field is called “Test Field” and the field in the related record from which I want to get the info is called “Line Up”:

    var test_field_id = ‘fld-49c13a65b1324a92941d51a895526d06’;
    var line_up = record.getFieldValue(‘fld-ece13baf855a423cb121bfde1167f1b4’);

    record.setFieldValue(test_field_id, line_up);
    form.saveAllChanges();

    console.log(line_up);

    Nothing appears in the target field, and the console entry reads “undefined”.

    Can TapForms perform this operation?

    October 31, 2019 at 1:27 AM #37604

    Sam Moffatt
    Participant

    If you are pulling from a JOIN field, you need to get the records in that JOIN. JOIN is a many to many type so you will get multiple records back:

    var joinRecords = record.getFieldValue('fld-nameofjoinfield');

    This will return you a list of records that you need to iterate over. If you look in the snippet editor there is a “child records loop” snippet that should help you if you select the field you care about and then do something useful with it.

    Depending on your use case, the result of last line of your script field will be used as the script field value. If you’re looking to pull values out then you can just leave a line with the variable in it that you want to show up in the field.

    Here’s an example of how you can combine multiple values from child Link to Form fields into a single value, this feels like it might be pertinent to your use case.

Viewing 1 reply thread

You must be logged in to reply to this topic.