0

Compare two fields

Hi!

I have a 'TableHere' table with 10 records and two text fields filled in:

Text1

Text2

I want to create a button that compares the two fields and tells me in which records the fields are not identical.

This is what I created, but it doesn’t work.

 

let afsel := (select 'TableHere');
for loop1 in afsel do
    let afid := loop1.ID;
    if loop1.Testo1 != loop1.'Testo2' then
        alert("Campi diversi nel record " + afid)
    else
        alert("Campi uguali")
    end
end

 

Copy

 

Where am I wrong?

Thank you

6 replies

null
    • Ninox developper
    • Jacques_TUR
    • 1 yr ago
    • Reported - view

    I think your code is right, but the alert message does not wait for the user to press ok. If another message comes, it replaces the previous one. So you can only see the last message displayed by the loop.

    Use the dialog to see all messages one by one: https://docs.ninox.com/en/script/function-overview/functions/dialog

      • Web_Namer
      • 1 yr ago
      • Reported - view

      Jacques TUR thank you!

      • Web_Namer
      • 1 yr ago
      • Reported - view

      Jacques TUR 

      I entered the follow code, and that’s fine.

      let afsel := (select 'Copia Incolla Cancella Paragona');
      for loop1 in afsel do
          let afid := loop1.ID;
          if loop1.Testo != loop1.'Testo 2' then
              let title := "ATTENTION";
              let message := "In this record there are different fields:" + afid;
              let answerOptions := ["OK"];
              if dialog(title, message, answerOptions) = "OK" then
                  void
              end
          else
              let title := "OK";
              let message := "This record is fine:" + afid;
              let answerOptions := ["OK"];
              if dialog(title, message, answerOptions) = "OK" then
                  void
              end
          end
      end

       

      Now I would like the dialogue to open only at the end and not for each record.

      I created this code but it doesn’t work

      let afsel := (select 'Copia Incolla Cancella Paragona');
      let afver := 0;
      for loop1 in afsel do
          let afid := loop1.ID;
          if loop1.Testo1 != loop1.Testo2 then
              let afver := 1;
              void
          end
      end;
      if afver > 0 then
          let title := "ATTENTION";
          let message := "There are different fields";
          let answerOptions := ["OK"];
          if dialog(title, message, answerOptions) = "OK" then
              void
          end;
          let title := "OK";
          let message := "There aren't different fields";
          let answerOptions := ["OK"];
          if dialog(title, message, answerOptions) = "OK" then
              void
          end
      end

      I understand that after tag "end" the variable is lost. Is it true?

      But other times Ninox gave me error, this time it doesn’t give me any code error.

       

      Thanks

    • Ninox developper
    • Jacques_TUR
    • 1 yr ago
    • Reported - view

    It's just because you declared the variable "afver" twice with the "let" statement. 

    Try this code: 

    let afsel := (select 'Copia Incolla Cancella Paragona');
    let afver := 0;
    for loop1 in afsel do
        let afid := loop1.ID;
        if loop1.Testo1 != loop1.Testo2 then
            afver := 1;
        end
    end;
    if afver > 0 then
        dialog("ATTENTION", "There are different fields", ["OK"])
    end
      • Web_Namer
      • 1 yr ago
      • Reported - view

      Jacques TUR I didn’t know that the let is only used once for the same variable. Thanks

      • Ninox developper
      • Jacques_TUR
      • 1 yr ago
      • Reported - view

      Web Name The word "let" is used to define a variable. If it is used twice, two different variables are defined.

Content aside

  • 1 yr agoLast active
  • 6Replies
  • 126Views
  • 2 Following