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
-
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
-
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
-
Where Script is a field to allow you to see the result of running your script instead of shown by an alert
-
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?
-
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
endThank 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