0

Regarding the issue of modifying a sub-table of a sub-table.

Created an order database. The Orders table records the product details of an order; the Products table records product names and quantities; the code table records code information, etc. I need to match the quantity in Products with the related code, so I set up a Matching Code button in Products. 

Now I need to set up a button in the Orders table with the same Matching Code function. When clicked, it will match all Products related to the Product Details in Orders. How should I edit the code?

19 replies

null
    • John_Halls
    • 6 mths ago
    • Reported - view

    Hi

    Your codes goes from this for one product line

    let aa := this;
    for i from 0 to nb do
        let newRec := (create Code);
        newRec.(Products := aa)
    end
    

    To this for all product lines in a order

    for aa in 'Product Details' do
        for i from 0 to aa.nb do
            let newRec := (create Code);
            newRec.(Products := aa)
        end
    end
    

    Regards John

      • gold_cat
      • 6 mths ago
      • Reported - view

       

      Thank you, John Halls, for your help. I would like to delve deeper into this topic. If I add a condition that matches when "nb" in Product Details is greater than or equal to 3, and shows a message "less than 3" if it is less than 3, is this possible to achieve?

      • Fred
      • 6 mths ago
      • Reported - view

      Can you go over the conditions again?

      If nb >= 3 then....

      if NOT then....

      • gold_cat
      • 6 mths ago
      • Reported - view

       

      Hi, Fred. If `nb >= 3`, execute the original code:

      ```
      let newRec := (create Code);
      newRec.(Products := aa);
      ```

      If `nb < 3`, display an alert:

      ```
      alert("nb < 3");
      ```

      • gold_cat
      • 6 mths ago
      • Reported - view

        like this

      • Fred
      • 6 mths ago
      • Reported - view

      That means multiple alert windows will pop up.

      Are you using new code?

      Where do you think the the if statement should go? Give it a try. Post where you think it might go. Even if you get errors, that is OK.

      • gold_cat
      • 6 mths ago
      • Reported - view

        It seems to have made it.

      for aa in 'Product Details' do
          for i from 0 to aa.nb do
              if aa.nb >= 3 then
                  let newRec := (create Code);
                  newRec.(Products := aa)
              else
                  if aa.nb < 3 then alert("nb < 3") end
              end
          end
      end
      
    • John_Halls
    • 6 mths ago
    • Reported - view

    Fred is right, it isn't reccommened to put alerts in a loop. I would set a text or choice field so that you can see the results of running your script. If it was a choice field called Script it would look like this

    for aa in 'Product Details' do
        for i from 0 to aa.nb do
            if aa.nb >= 3 then
                let newRec := (create Code);
                newRec.(Products := aa);
                aa.Script := 1
            else
                aa.Script := 2
            end
        end
    end
    
    
      • gold_cat
      • 6 mths ago
      • Reported - view

       

      I used code with alerts, and if there are two or more items in the 'Product Details' section that need to trigger an alert, it will only show the alert once (I'm not sure if this is correct). Additionally, the code you wrote, 'aa.Script := 1&2', what does that mean?

    • John_Halls
    • 6 mths ago
    • Reported - view

    Where Script is a field to allow you to see the result of running your script instead of shown by an alert

      • gold_cat
      • 6 mths ago
      • Reported - view

        Thank you, John Halls, for your response.

    • Fred
    • 6 mths ago
    • Reported - view

    Well that is weird, I tried out your code and Ninox only shows an alert for the last record that doesn't match the criteria. I would have thought an alert would've popped up for each instance of Product Detail that has an nb of less than 3.

    If you put this in a button on the Order table:

    for aa in 'Product Details' do
        if aa.nb >= 3 then
            alert(aa.name + " - More than 3")
        else
            alert(aa.name + " - Less than 3")
        end
    end

    Then go to the 2nd record with 3 items. Change the value in nb of one Product Detail to 3 or greater. Then press the button and it will only show an alert for the one positive. It should show an alert for each record in Product Detail? Am I wrong? Did alerts() get changed?

      • Fred
      • 6 mths ago
      • Reported - view

      This happens in both the public cloud and local DB with app v3.12.2.

      • gold_cat
      • 6 mths ago
      • Reported - view

       It seems that this issue cannot be resolved at the moment.

      • Fred
      • 6 mths ago
      • Reported - view

      Ninox says to use dialog() instead of alert(). Ninox shows each alert but does not pause in between loops, so the alerts are stacked. I guess dialog() does pause properly.

      • gold_cat
      • 6 mths ago
      • Reported - view

       

       said:
      I have modified the code above, but the prompt still pops up twice (it should only appear once). Is there something wrong with my code? 

       After multiple rounds of testing, this issue still persists.

      • Fred
      • 6 mths ago
      • Reported - view

       You can use alert() since you only want one pop up to appear. Just be aware that if they make any changes you could see many. I’ll post a possible change to the code later so only 1 pop up will appear.

      • gold_cat
      • 6 mths ago
      • Reported - view

       Waiting for release

    • gold_cat
    • 6 mths ago
    • Reported - view

     said:
    for aa in 'Product Details' do
    for i from 0 to aa.nb do
    if aa.nb >= 3 then
    let newRec := (create Code);
    newRec.(Products := aa)
    else
    if aa.nb < 3 then alert("nb < 3") end
    end
    end
    end

    Thank you, Fred, for continuing to look into this issue. I have modified the code above, but the prompt still pops up twice (it should only appear once). Is there something wrong with my code? 

    let title := "Tips";
    let message := "nb<3";
    let answerOptions := ["OK"];
    for aa in 'Product Details' do
        for i from 0 to aa.nb do
            if aa.nb >= 3 then
                let newRec := (create Code);
                newRec.(Products := aa)
            else
                if aa.nb < 3 then
                    dialog(title, message, answerOptions)
                end
            end
        end
    end

    I found the problem, and it seems to be correct after changing it to a switch statement.

    let title := "Tips";
    let message := "nb<3";
    let answerOptions := ["OK"];
    for aa in 'Product Details' do
        for i from 0 to aa.nb do
            switch true do
            case aa.nb >= 3:
                (
                    let newRec := (create Code);
                    newRec.(Products := aa)
                )
            case aa.nb < 3:
                dialog(title, message, answerOptions)
            end
        end
    end

Content aside

  • Status Answered
  • 6 mths agoLast active
  • 19Replies
  • 97Views
  • 3 Following