Calling a child field value

Viewing 4 reply threads
  • Author
    Posts
  • May 24, 2024 at 5:19 AM #50748

    Chas Mac Donald
    Participant

    I’ve spent three days trying to do this, so if this is an annoyingly simple thing, I apologise!

    I have two Forms – F01a and F04a

    F01a has various fields, the important ones are MatTar and TarNam
    F04a has various fields, the important ones are TarRef and TarCln

    I want to use F01a.MatTar to link to F04a.TarRef where equal and return Fo4a.TarCln into F01a.TarNam

    I could this in MSAccess with my eyes shut, but I believe this is Java and I just can’t get it. I’m also working on an ipad 🙄

    Save my mental health, pleeeeeez 🙂

     

    May 24, 2024 at 9:14 AM #50751

    Daniel Leu
    Participant

    First you have to link the two forms. In F01a, create a link to form field and give it a name (eg link). Then set the link type to join, select F04a as the form to link to and use the MatTar and TarRef fields for the values.

    Next turn F01a.TarNam into a script field. Following field script should do the trick. I have added comments to describe what I’m doing:

    function getTarCln() {
       // get F014a form
       let f04a_form = document.getFormNamed("F04a");
       // get field id for TarCln
       let tarCln__f04a_id = f04a_form.getFieldNamed("TarCln").getId();
       // get field id for link field
       let link_id = form.getFieldNamed("link").getId();
       // get linked records
       let f04a_recs = record.getFieldValue(link_id);
       // check that there's only one record
       if (f04a_recs.length > 1) {
          console.log("Error, more than one record");
          return;
       }
       // get value from F014a form
       let value = f04a_recs[0].getFieldValue(tarCln__f04a_id);
       console.log("Value fetched: " + value);
       // done, return value
       return value;
    }
    getTarCln();
    This script assumes that the field that links the two forms together is called link. You can change this on line 10.
    The return type of the script must match your field type, eg Number, Text, Date.
    This is JavaScript and not Java. Although they share part of their name, they are totally different beasts.
    May 25, 2024 at 1:34 AM #50754

    Chas Mac Donald
    Participant

    Daniel,

    I’m a bit busy at the moment, so I’ll get a look at this as soon as I can. Meanwhile, thank you for your time and assistance. It is appreciated. 🙂

    May 25, 2024 at 9:12 AM #50757

    Chas Mac Donald
    Participant

    Daniel, That all works fine, thanks … except that it does not put the value into the TarNam field where I want it. It’s in the results and console log, but not in the form field. Is there something missing?

    May 25, 2024 at 1:38 PM #50758

    Chas Mac Donald
    Participant

    Update: I got it to work 🙂 I have no recollection how 😂 But hey ho!

    May 29, 2024 at 10:43 AM #50765

    Daniel Leu
    Participant

    Hi Chas, thank you for letting me know that it works for you! Yeah!

Viewing 4 reply threads

You must be logged in to reply to this topic.