Displaying linked fields

Tagged: 

Viewing 8 reply threads
  • Author
    Posts
  • November 20, 2019 at 3:13 PM #38132

    Martin Inchley
    Participant

    There are two things I would like to do, which I think may not be possible, but someone may know differently…

    1. Display a field from a linked form without it obviously being enclosed within the “Link to Form” field that was used to set up the link. I want it to appear like any other field on a layout.

    2. Display a field that is two links away. Form A links to Form B. Form B links to Form C. I would like to display a field from Form C on a layout associated with Form A.

    Anyone know anything about this…?

    November 20, 2019 at 4:30 PM #38133

    Daniel Leu
    Participant

    You can do both with a field script.

    1. Display a field from a linked form without it obviously being enclosed within the “Link to Form” field that was used to set up the link. I want it to appear like any other field on a layout.

    var child_link_id = 'fld-c22501cc3910474aa1c59387fde30d82';
    var child_name_id = 'fld-8b8f3b0cd59b4b4c9180a8903685e7ee';
    
    var childs = record.getFieldValue(child_link_id);
    
    // show first child
    childs[0].getFieldValue(child_name_id);

    First I define the child link field id (in the parent form) and the name field id from the child form. Next I fetch all childs. Assuming I only have one child record, I just fetch the name of the first record found.

    If there is more than one child record, I can simply loop over them:

    // combine child names
    var child_names = [];
    for (child of childs){
    	child_names.push(child.getFieldValue(child_name_id));
    }
    child_names.concat();

    2. Display a field that is two links away. Form A links to Form B. Form B links to Form C. I would like to display a field from Form C on a layout associated with Form A.

    If I want to get data form a child’s child form, eg grandchild, the process is very similar. Following script just returns the name of the first grandchild record from the first child record:

    var child_link_id = 'fld-c22501cc3910474aa1c59387fde30d82';
    
    var grandchild_link_id = 'fld-9d399af0d72b4c8fbc3cb95fa6127203';
    var grandchild_name_id = 'fld-9485e9dd29474745acee87bb3a60fff5';
    
    var childs = record.getFieldValue(child_link_id);
    
    // get grandchildren from first child
    var grandchildren = childs[0].getFieldValue(grandchild_link_id);
    
    // get name of first grandchild
    grandchildren[0].getFieldValue(grandchild_name_id);

    To get the ids for the granchield fields, I opened a field script in the child form and copied the necessary entries over to the field script in the parent form.

    November 20, 2019 at 4:41 PM #38135

    Martin Inchley
    Participant

    That’s very helpful, Daniel. Because I came to Script Fields after first experimenting with Form scripts and the TapForms JavaScript API, I have up until now been using them to achieve an action rather than present a result.

    November 20, 2019 at 4:50 PM #38136

    Daniel Leu
    Participant

    Script fields are very powerful vehicles to fetch, format, and process data from different forms, among others.

    November 21, 2019 at 2:54 AM #38147

    Martin Inchley
    Participant

    This technique, of course, doesn’t show the actual field you are referencing. It just gets its contents into a script field in the current form.

    Ideally it would be nice to show the actual field so that you could edit it.

    November 21, 2019 at 9:39 AM #38154

    Daniel Leu
    Participant

    Ideally it would be nice to show the actual field so that you could edit it.

    Ahh… you want to edit the field at the same time? Just like that it’s not possible. You would need a helper script that copies edited code back to the child field.

    November 22, 2019 at 1:04 AM #38165

    Sam Moffatt
    Participant

    I think the challenge with popping up edit controls from two forms away is making sure you knew which record you’re editing because if you’re using a Link to Form field, there could be multiple child values.

    I dug out my old Access install because I remembered they did something like that in the form designer where you could put in fields from another table and it’d let you navigate around them. You could define subviews that reused what Tap Forms calls layouts to be able to change related fields and if you had a single record relationship it let you just drag that field onto the form designer.

    Is that sort of what you’re thinking?

    November 22, 2019 at 5:24 AM #38174

    Martin Inchley
    Participant

    I completely agree about the need to be aware of which related record you’re seeing. That certainly has to be part of the design process, rather than taking a guess on the fly!

    I come to this from a FileMaker Pro background, where putting fields from a related table onto a layout is as easy as fields from the current table. If it’s a one-to-many relationship, it’s the value from the first record in the related table that shows, so you have to be careful. But (a) it’s really useful with one-to-one relationships, and (b) there is also a way of presenting results from multiple records (a bit like a TF link-to-form field), and that can include fields that are two steps away.

    I’m not expecting TapForms to do what FileMaker can – that would be unfair. But working out how to do more, and in a prettier fashion, that’s an interesting challenge! Especially when you’re trying to make it easier for someone else.

    November 22, 2019 at 1:43 PM #38188

    Brendan
    Keymaster

    @Martin, that’s where the power of Scripting comes in. You can build scripts that expose the data further up the relationship chain from lower down. Although in general that’s a read-only thing. I agree though, it would be nice to be able to put editing controls in Tap Forms from anywhere down the relationship hierarchy. Doesn’t mean I’ll ever build that. But I understand the desire.

Viewing 8 reply threads

You must be logged in to reply to this topic.