0

Checking if a record has been linked to another one

Today I noticed an unexpected (to me - as non professional coder) behaviour when checking if a record is linked to another one. I haven't found info about it in the forum nor the documentation, so I post it here.

It is about checking if a record is linked to another one. 
For example:
When I needed to check if a Record (for instance a "Service") had been linked to another record (for instance "Invoice"), through a field called "Link to Invoice" I was using a formula like this in Service > Display invoice Nr > Formula:

if 'Link to Invoice' = null then
"No invoice linked to this service"
else
'Link to Invoice'.'Invoice Nr'
end

{This is just a simplified example}

However today I noticed that if an invoice was linked, but then the link was removed,  Link to Invoice = null will return "false".
This was unexpected to me. I've introduced the following check now:

if 'Link to Invoice' = null then
"No linked invoice to this service"
else
    if 'Link to Invoice' = "" then
    "There was a linked Invoice but it has been removed"
    else
    'Link to Invoice'.'Invoice Nr'
    end
end

I found this behaviour strange... the check 'Link to Invoice' = "" will return false if there is a linked record (normal) but also if there is no record linked (strange?).
I have only found it to return true if there was a record linked but it has been removed. 

{With my very limited knowledge, I guess that Ninox created a "pointer" to the record when the link is created. Then when the link is removed, that pointer is not eliminated, but all the "fields within it" are emptied ???}

Is this an expected behaviour to advanced coders?
Is there a better way to do this sort of checks? (For instance using count('Link to Invoice'))

3 replies

null
    • Fred
    • 1 yr ago
    • Reported - view

    How are you unlinking the records?

    I have this code in a formula field in my table GAMESTATS:

    if Teams = null then 1 else 0 end
    

    Teams is the 1 in a 1:N relationship to GAMESTATS.

    If I use the unlink button:

    The formula returns a 1.

    If I use a button to unlink with:

    Teams := 0
    

    The formula also returns a 1.

    • Elena_Rodriguez
    • 1 yr ago
    • Reported - view

    I was unlinking them using the button. 
    The "Service" in the example is the 1 side in the 1:N relation.
    I use the web app. 

    • Fred
    • 1 yr ago
    • Reported - view
     said:
    Is there a better way to do this sort of checks? (For instance using count('Link to Invoice'))

     This would also be a valid way of checking if records exist or not.

Content aside

  • 1 yr agoLast active
  • 3Replies
  • 114Views
  • 2 Following