0

Issue with trigger conditions in 'Liste' Field: Multiple Text conditions not triggering as expected

I have an issue with a trigger in the 'Liste' field. I would like to create multiple triggers in the 'Liste' field that check if certain text is contained within it. For example, if the text 'Americana H' is contained, then it should select the first record from the 'Zertifikate' dynamic multiple-choice field list. Then, if the text 'Boden lackiert' is also contained, it should also select the second one, and so on. My problem is that if I input two or more triggers, it always checks only one condition. I am attaching the screenshot and the table "Allegati" to which the 'Zertifikate' dynamic multiple-choice field refers.

 

if contains(Liste, "Americana H") then
    Zertifikate := [1]
end;
if contains(Liste, "Boden lackiert") then
    Zertifikate := [2]
and so on

13 replies

null
    • John_Halls
    • 7 mths ago
    • Reported - view

    Hi. Unfortunately, it's not quite as simple as that. Have a look at this post

    https://forum.ninox.com/t/83hrts2#y4hrsgn

    Regards John

    • Fred
    • 7 mths ago
    • Reported - view

    What kind of field is Liste?

      • Walcher_Messebau
      • 6 mths ago
      • Reported - view

       it’s a text field. In essence, I need to copy a text into this box. Based on the content of the text, it selects the corresponding boxes from "Zertifikate". This way, I get PDFs that appear as certificates to print according to the list. Doing so still leaves the option to manually select the "Zertifikate" boxes as well.

    • Fred
    • 7 mths ago
    • Reported - view

    Another question is what are you trying to accomplish?

    Is a user supposed to type in Liste? If the user is supposed to type then it seems like an extra step when they can just select the correct records.

    Or how is the text generated in Liste? If so then maybe you need to go back a step or two in your process to figure out if you can update this dynamic multichoice (dMC) an another step.

    • Fred
    • 6 mths ago
    • Reported - view

    You can try the following in a button to test it out:

    let getAllegatiRec := (select Allegati where Aktiv = 1);
    let makeArray := split(Liste, ", ");
    let getSelectedAllegatiRecs := for loop1 in makeArray do
            getAllegatiRec[Descrizione = loop1]
        end;
    Zertifikate := getSelectedAllegatiRecs

    I've tried to fill in your details as best I could so there could still be errors.

    Line 1, I create a variable that gets the same records as the dMC field.

    Line 2, I create an array of the test field Liste. This will only work as long as the names do not have a "," in their names.

    Lines 3-5, another variable is created that stores an array of records from the variable in Line 1 that matches each item of the newly created array of the text fields in Liste.  I noticed that the text in Liste do not match perfectly with the Descrizione field. This code is setup for exact match. You can try "like" instead of equals. Or we can try other options if like doesn't work.

    Line 6, lucky for us Ninox now allows us to set multi choice fields with arrays, so now that we have an array of records from Allegati that we want we can set the Zertifikate dMC field to our new array.

    Once everything works, then you can transfer the code into the Trigger after update of Zertifikate.

    Try to get comfortable with making and manipulating arrays as that will take you far in writing scripts that can manage your database.

      • Walcher_Messebau
      • 6 mths ago
      • Reported - view

       Thank you! It took me a while to understand the formula. I changed a couple of things. Within the "Allegati" table, I created a text field "Keyword". This field contains keywords separated by commas. Based on the words contained in this "Keyword" field, the formula should search for matches. The formula has been modified and adapted and seems to work, but it still applies the logic only to the first match and not to the subsequent ones.

      let getAllegatiRec := (select Allegati where Aktiv = 1);
      let makeArray := split(Liste, ", ");
      let getSelectedAllegatiRecs := for loop1 in makeArray do
              getAllegatiRec[contains(Keyword, loop1)]
          end;
      Zertifikate := getSelectedAllegatiRecs
      
      • Fred
      • 6 mths ago
      • Reported - view

      What does the data in Keywords look like?

      • Walcher_Messebau
      • 6 mths ago
      • Reported - view

       

      It's a simple text field that contains keywords. If any of these words match with a word in the text field 'Liste', it has to flag the corresponding field in the dMC 'Zertifikate'. It works but only for the first match

      • Walcher_Messebau
      • 6 mths ago
      • Reported - view

       

      • Walcher_Messebau
      • 6 mths ago
      • Reported - view

       It works with more then one match? Can you paste the code? Something has to be different in your code

      • Fred
      • 6 mths ago
      • Reported - view

      here is the db. I tried it both cloud and local/icloud and they both function the same.

      If you go to the Dashboard, you will see:

      dMC

      Liste

      check

      at the top of the page.

      the dMC points to Table2 and it shows the rec Id and the contents of a field called Text, which is what I use in the contains().

      Liste is a text field

      the check formula field shows you the matching records from Table2 which you can verify with the dMC. I can use either the word or the number. It matches the number after the word, not the record Id. So if you type in 8 to Liste it will return record 2.

      • Walcher_Messebau
      • 6 mths ago
      • Reported - view

       Here I am! There have been several complications regarding the check for possible matches between the "List" field and the "Keyword" field. The first issue was that it wasn't working because the Keywords were not separated by commas, and in the "List" field, there were also no commas. This is why it stopped at the first match. Consequently, being article codes, I preferred to create a table called "Table1" with the respective codes in the "Art." field instead of the "Keyword" field. Then there was another problem because some codes matched the text in the "List" but continued with **A, **B, etc., for an internal matter. Therefore, it did not recognize the codes. The final and perfectly working code is the folowing. Thanks a lot for your help :)

      let getAllegatiRec := (select Allegati where Aktiv = 1);
      let replacedListe := replacex(Liste, " ", ",");
      let makeArray := split(replacedListe, ",");
      let getSelectedAllegatiRecs := for loop1 in makeArray do
              if contains(loop1, "**") and length(loop1) > 3 then
                  let baseCode := substring(loop1, 0, length(loop1) - 3);
                  let existsInTabella1 := count(select Tabella1 where 'Art.' = baseCode) > 0;
                  if existsInTabella1 then
                      getAllegatiRec[contains(Tabella1.'Art.', baseCode)]
                  else
                      null
                  end
              else
                  let existsInTabella1Direct := count(select Tabella1 where 'Art.' = loop1) > 0;
                  if existsInTabella1Direct then
                      getAllegatiRec[contains(Tabella1.'Art.', loop1)]
                  else
                      null
                  end
              end
          end;
      let filteredAllegatiRecs := for rec in getSelectedAllegatiRecs do
              if rec != null then rec end
          end;
      Zertifikate := filteredAllegatiRecs;
      Liste := replacedListe

Content aside

  • Status Answered
  • 6 mths agoLast active
  • 13Replies
  • 85Views
  • 3 Following