• Detecting No Related Records

    From Charles H. Sampson@21:1/5 to All on Mon Jul 29 18:13:20 2019
    How do I detect that a record has no related records? I've found that
    "Go To Related Record" doesn't protest if there are no related records
    so catching an error doesn't work. I've also searched the Get functions
    for something that returns a count of related records to no avail.

    Charlie
    --
    Nobody in this country got rich on his own. You built a factory--good.
    But you moved your goods on roads we all paid for. You hired workers we
    all paid to educate. So keep a big hunk of the money from your factory.
    But take a hunk and pay it forward. Elizabeth Warren (paraphrased)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Helpful Harry@21:1/5 to Charles H. Sampson on Tue Jul 30 13:27:55 2019
    On 2019-07-30 01:13:20 +0000, Charles H. Sampson said:

    How do I detect that a record has no related records? I've found that
    "Go To Related Record" doesn't protest if there are no related records
    so catching an error doesn't work. I've also searched the Get functions
    for something that returns a count of related records to no avail.

    Charlie

    There's probably a few ways, but perhaps the easiest is to simply count
    the number of related records using a related field that must always
    contain data - the obvious one being the related records' Child-Key
    field itself. In the Parent Table, you can create a Calculation field
    like:

    NumRelatedRecords Calculation, Number Result
    = Count(Relationship::Related_Child_KeyField)

    or you can simply use the same calculation in a Script, within an If statement's test for example..

    If that calculates as zero, then there are no related records.

    You may even already have that field in the Parent Table since it can
    often be handy to display the count underneath a Portal.


    Helpful Harry :o)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Charles H. Sampson@21:1/5 to Helpful Harry on Tue Jul 30 19:27:23 2019
    Helpful Harry <HelpfulHarry@BusyWorking.com> wrote:

    On 2019-07-30 01:13:20 +0000, Charles H. Sampson said:

    How do I detect that a record has no related records? I've found that
    "Go To Related Record" doesn't protest if there are no related records
    so catching an error doesn't work. I've also searched the Get functions
    for something that returns a count of related records to no avail.


    There's probably a few ways, but perhaps the easiest is to simply count
    the number of related records using a related field that must always
    contain data - the obvious one being the related records' Child-Key
    field itself. In the Parent Table, you can create a Calculation field
    like:

    NumRelatedRecords Calculation, Number Result
    = Count(Relationship::Related_Child_KeyField)

    or you can simply use the same calculation in a Script, within an If statement's test for example..

    If that calculates as zero, then there are no related records.

    You may even already have that field in the Parent Table since it can
    often be handy to display the count underneath a Portal.

    Helpful Harry :o)

    Worked like a champ, Harry. Thanks yet again. You'd think (or at least I
    would think) that with the many Get functions, not a few of them having
    to do with the number of records in a set, there would be one something
    like Get (RelatedRecordsCount).

    Charlie
    --
    Nobody in this country got rich on his own. You built a factory--good.
    But you moved your goods on roads we all paid for. You hired workers we
    all paid to educate. So keep a big hunk of the money from your factory.
    But take a hunk and pay it forward. Elizabeth Warren (paraphrased)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From none@gmail.com@21:1/5 to Charles H. Sampson on Wed Jul 31 20:35:37 2019
    On 31-7-2019 04:27, Charles H. Sampson wrote:
    Helpful Harry <HelpfulHarry@BusyWorking.com> wrote:

    On 2019-07-30 01:13:20 +0000, Charles H. Sampson said:

    How do I detect that a record has no related records? I've found that
    "Go To Related Record" doesn't protest if there are no related records
    so catching an error doesn't work. I've also searched the Get functions
    for something that returns a count of related records to no avail.


    There's probably a few ways, but perhaps the easiest is to simply count
    the number of related records using a related field that must always
    contain data - the obvious one being the related records' Child-Key
    field itself. In the Parent Table, you can create a Calculation field
    like:

    NumRelatedRecords Calculation, Number Result
    = Count(Relationship::Related_Child_KeyField)

    or you can simply use the same calculation in a Script, within an If
    statement's test for example..

    If that calculates as zero, then there are no related records.

    You may even already have that field in the Parent Table since it can
    often be handy to display the count underneath a Portal.

    Helpful Harry :o)

    Worked like a champ, Harry. Thanks yet again. You'd think (or at least I would think) that with the many Get functions, not a few of them having
    to do with the number of records in a set, there would be one something
    like Get (RelatedRecordsCount).

    Charlie

    It's is easy to DIY, you can easily adapt it to your needs.

    calculated field that returns text
    c_IsRelValid =
    Case(
    IsEmpty(Count(MyRelatedTable::MyRelatedPrimaryID));"There are no related records";
    Count(MyRelatedTable::MyRelatedPrimaryID)=1;"There is 1 related record";
    "There are " & GetAsText(Count(MyRelatedTable::MyRelatedPrimaryID)) & "
    related records")

    Erik

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)