Code Simplification - Loop ?
Hello,
I am trying to simplify this code
Basically I have two very similar tables, the current working table, only num (Deduction) is a dynamic choice that selects the other table that has the identical fields.
In Deduction, I have a trigger after update that will go through and copy the field details from 'Taxes/Deductions' table, only if values are present.
I currently have if then statements for each 'Taxes/Deductions'.Field checking for a value, if value is not null then it will copy the field details.
There has to be a way to loop through each field, and if not null, copy the data.
Can someone assist me in achieving this?
Thank you,
S. Moore
3 replies
-
Your thinking of using a for loop command is a good direction.
Here is one possibility that you can put in a button:
Lines 1 - 3 are similar to yours.
Lines 4 - 6 check if the fields are true then assigns a value. otherwise the variable is empty.
Line 7 creates an array of the check fields above. Only fields that are true will show up here.
Lines 8 - 17 is the for loop command that takes the array from line 7 and uses the switch command to check each field that needs to be updated.
I might have missed a translation into your DB names, so double check for my errors.
-
Fred,
This is great. It is exactly what I was looking for, however, my goal was to simplify my code. I do think my if/then is a little simpler than the while loop. Only because each case (n1check) still needs an if/then.
However, this example does give me a much better understanding of loops within Ninox... Something I would love to be more familiar with.
-
S Moore I don't think using a loop makes sense here as those calculations are static. Loops are more for dynamic data like table rows or DMC.
Content aside
- Status Answered
- 2 yrs agoSat, December 17, 2022 at 10:51 AM UTCLast active
- 3Replies
- 78Views
-
3
Following