Complex criteria for Select
Hi,
I am working on a project which requires a dynamic choice field to be populated by the results of a select based on one or more of four criteria. The criteria are selected at the top of a dashboard. I can set the code to populate the choice field for anyone of the criteria, but to cater for the any one or more scenarios, 12 I think, would result in a humungous block of if..then..else.
I had hoped to solve this by running a series of select statements on the result of the previous one. However, unlike SQL, Ninox doesn't seem to be able to make a temporary table from the results of a select, only an array. Nor does it seem possible to run a select on an array.
Any suggestions on how to go about this?
On this screen shot the criteria are the 4 fields at the top and the choice field is at the bottom.
20 replies
-
Hi, try the following:
let x := text(Filter by Status); let y := text(Filter by Camera); let z := text(Filter by Film Stock); let i := text (Filter by Format); select Film where Status = x and Camera = y and 'Film Stock' = z and Format = i;
-
As you have some "Show All" options you may need to build your where clause as a text string and evaluate it, such as
let x := text(Filter by Status); let y := text(Filter by Camera); let z := text(Filter by Film Stock); let i := text (Filter by Format); let theFilter := if x = "Show All" then "true and " else "Status = x and "; theFilter := theFilter + if y = "All" then "true and " else "Camera = y and "; theFilter := theFilter + if z = "" then "true and " else "'Film Stock' = z and "; theFilter := theFilter + if i = "" then "true" else "Format = i" select Film[eval(theFilter, this)]
Regards John
-
Do your records in Film also have reference fields to Status, Camera, Film Stock, and Format? That will make filtering/search easier.
said:
I had hoped to solve this by running a series of select statements on the result of the previous one.What Ninox can do is filter arrays. So you could do something like:
let t := this; let allRecords := select Film; let filter1 := allRecords[Status = number(t.'Filter by Status')]; let filter2 := filter1[Camera = number(t.'Filter by Camera')]; etc
This is not a solution for you question, but just information.
-
Thanks Fred. Yes, there are reference fields and filter is interesting, it is similar to the solution I was seeking. Yet again "this", is there a crib sheet for when to use it?
-
The simplest solution I can think of is the following:
let x := text(Choice1); let y := text(Choice2); select Film where switch true do case x != "Show All": Status = x case y != "All": Format = y end
-
Thanks for your contributions chaps. Cracked it!
let t := this;
let myRecordSet := rsort((select Film) order by 'Index Number');
if t.'Filter by Status' < 7 then
let myfilter := myRecordSet[Status = number(t.'Filter by Status')];
myRecordSet := myfilter
end;
if t.'Filter by Format' < 4 then
let myfilter := myRecordSet['Film Format' = number(t.'Filter by Format')];
myRecordSet := myfilter
end;
if 'Filter by Camera' != null then
let myfilter := myRecordSet[Camera = number(t.'Filter by Camera')];
myRecordSet := myfilter
end;
if 'Filter by Film Stock' != null then
let myfilter := myRecordSet['Film Loaded' = number(t.'Filter by Film Stock')];
myRecordSet := myfilter
end;
myRecordSet
Content aside
- Status Answered
- 3 mths agoLast active
- 20Replies
- 92Views
-
6
Following