With the launch of the new Ninox v3.3.0, we now have an excellent feature where we can finally create dynamic choices. Andy has covered parts of this topic already, but I would like to discuss specifically how to handle them and how to refer to records.
Most people probably use the “Link” (relationship) field as a single choice. When we are not actually linking one table to another, for example a customer to an invoice, I prefer to use the dynamic choice field. For values you simply use the “select Table Name” and for the Value Name, you pick the field that you want to be displayed in the drop down, like ‘Customer Name’.
In this situation we cannot refer to the actual record itself immediately. What we get as result is the Record ID number. A single dynamic choice is simple, we get one number. I use the number(‘Dynamic Single Choice’) to get the ID. How do I get the record?
let xRecID := number(‘Dynamic Single Choice'); let xRec := record(‘Table Name', xRecID)
From this point, I can call any fields using the xRec.‘Field Name’ from this record.
The question is how can we get the record IDs for a multi choice field? It will be a shocking revelation. Use the numbers(‘Dynamic Multi Choice’). Notice the “s” at the end. This will list all selected choices as numbers. Do you want to add to it with code? Let’s say we have options 1-5. Two and three are selected:
let xSelection := numbers(‘Dynamic Multi Choice'); => this returns [2,3] let xNewArray := array(xSelection, ) => this will return [2,3,4]
How do we take an item away from the array? Let’s take a look at an example. The original array will have three items in it and we will take away one of them.
let xArray := [“One”, “Two”, “Three”]; let xArrayCnt := cnt(xArray); for i in range(0, xArrayCnt) do if item(xArray, i) != “Two” then item(xArray, i) end end
This will give us a result of [“One”, “Three”]
Now you and your app end-users can have complete control over the selectable options that appear in choice and multiple choice fields.