create options in choice field from variable/loop
It's easy to fill a dynamic Choice field with options from a table/query but how to dynamically create options through something like
var options:=[]
for i from 1 to 3 do
options:=options + i
end;
options
resulting in options 1,2,3.
17 replies
-
To the best of my limited knowledge dynamic fields are table based, either through a select or reference field.
If you want to script the creation of choices in your dynamic field then you can just use the same script to create new records in the table you use as the base.
-
A Choice (dynamic) field is defined by an array of records. Any way to build an array of records may be used. Of, course, a "select" statement, or the dereferencing of a table reference are obvious ways to produce an array of records. But there are lots of alternatives, like for example making use of the fact that a "for" loop returns a array For example:
let t := Select Table1; for f in unique(t.Field) do first(t[Field = f]) end order by Field
In this example, "Table1" has many records, but "Field" has only a few different values. The formula builds an array of records from Table1, containing one record for each value of "Field".
-
In my case, the options are numeric and calculated, so the may be 1,2,3,4 another time 33,45,556,24667. I don't think it's efficient to do this with a table that has all potential numbers and then filter your way back...
-
Here is variation, with a better separation of the preparation of the dynamic choice field and its actual use. It also corrects a rather stupid error (a "let" in the wrong place…).
-
that's quite a smart solution, thnx
-
This is a related follow-up, but slightly different.
I need to parse through a JSON array [{"IO":5},{"IO":6}]. A dynamic choice should show only those records of table IOs that have the Id 5 or 6 (i.e. all values of the key IO in the JSON).
IOs[for option in my_JSON do IOs.Id = number(item(option, "IO")) end]
This does not work but returns all records of IO. How can the filter map against an array?
Content aside
- Status Answered
- 9 mths agoLast active
- 17Replies
- 280Views
-
5
Following