0

if statement

Hello everyone and happy new year!

I have this situation:

-Table1 with a Code text field

-Table2 with a Key text field and a button

This is the formula on the button

if Key = Table1.Code then
   alert(“Right”)
else
  alert(“wrong”)
end

So, if I write someting on the Code field and the same on the Key field, I always get the same message: wrong!

Why?

Thank you

 

6 replies

null
    • Alain_Fontaine
    • 3 yrs ago
    • Reported - view

    It seems that you established a relation between your tables by creating a reference field. But in what direction? I mean, if, in the fields of Table2, you look at the Reference field named Table1, is it 1:N or N:1?

    • Vincenzo_Martusciello
    • 3 yrs ago
    • Reported - view

    I have tried both ways. if both fields are empty I get it Right. 

    • Alain_Fontaine
    • 3 yrs ago
    • Reported - view

    It works as expected in my mockup of your database... Could you, in Table2, create a formula field containing: “debugValueInfo(Table1.Code)” and post the result?

    • Vincenzo_Martusciello
    • 3 yrs ago
    • Reported - view

    Done

    I get “string(undefined)”

    • CISOFT_Sarl
    • 3 yrs ago
    • Reported - view

    Table1.Code What it is?

     

    I think you must first select a record in your Table1 and after you can work with them.

    Basically :

     

    let myItem := (select Table1 where ID = yourIDYouNeed).Code;

    //Verify if your item is empty or more than one.

    if cnt(myItem) = 0 or cnt(myItem)>1 then

    alert(“I find 0 item or more 1);

    ”Make nothing“;

    void;

    else

    alert(”I find 1 and only 1 item);

    “Make your business logic here”;

    end

    • Alain_Fontaine
    • 3 yrs ago
    • Reported - view

    This seems to indicate that there is no record from Table1 linked to the current record in Table2. Did you establish a link, for example by using the magnifying glass associated with the reference field?

Content aside

  • 3 yrs agoLast active
  • 6Replies
  • 861Views