Seeking correct syntax to populate a multiplechoice field programmatically
I have a multiplechoice field Checklist that I want Ninox to programmatically populate with a set of possible conditions (e.g., say, Condition #1, #2, #3, &/or #4).
When I do something like the following:
if condition 1 then chosen(Checklist := 1) end;
if condition 2 then chosen(Checklist :=2) end; ... etc.,
... I am left with Checklist showing only the last true condition. The rest are overwritten. What is the correct syntax to force a multiplechoice field to retain all true conditions in a series of logic checks, rather than only the last one?
Thanks for your assistance.
3 replies

This is not yet possible with multiple choice fields. We are working on this. This will be available with an upcoming update.
Birger

I wanted to be able to select and unselect choices within a multiple choice field too. I also wanted to validate the changes the user made. I used the 'Trigger on update' on the multiple choice field.
This solution has to do with the state of an invoice. There are 6 choices. Some combinations are allowed others are not.
There are 3 steps:
1) Know what the change was by subtracting the current state of the selections from the previous state of the selections
Power here starts at:
for cb in cd do
And ends with:
sw := cz  cx;
2) Figure out what was allowed and not allowed based on that
switch sw do
3) Set it right and provied feedback if a correction was made.
InvoiceType := x;
vInvoiceTypeFlags := concat(x)
I've annotated the code with // to help and stripped out a bunch of cases to (...) to make it easier
// InvoiceType is the multiple choice field
// vInvoiceTypeFlags is a text field that mirrors InvoiceType and is used to determine what the change to Invoice type is
// “w” is how I comment the sections since // and /* don’t exist yet
//
//
// Determine the selected state of each of the multiple choice assigning the position number to each choice
let a := if contains(concat(InvoiceType), "Deposit") then 1 else null end;
let b := if contains(concat(InvoiceType), "Progress Payment") then 2 else null end;
let c := if contains(concat(InvoiceType), "FinalPayment") then 3 else null end;
let d := if contains(concat(InvoiceType), "Change Order") then 4 else null end;
let e := if contains(concat(InvoiceType), "Project Totals") then 5 else null end;
let f := if contains(concat(InvoiceType), "YTD Sub Totals") then 6 else null end;
//
// Determine the previous states of the multiple choice
let sa := contains(vInvoiceTypeFlags, "1");
let sb := contains(vInvoiceTypeFlags, "2");
let sc := contains(vInvoiceTypeFlags, "3");
let sd := contains(vInvoiceTypeFlags, "4");
let se := contains(vInvoiceTypeFlags, "5");
let sf := contains(vInvoiceTypeFlags, "6");
//
// Set up some variables and constants
let i := InvoiceNumber;
let w := null;
let ca := split(vInvoiceTypeFlags, ",");
let cb := null;
let cc := concat(chosen(InvoiceType));
let cd := ["Deposit", "Progress Payment", "Final Payment", "Change Order", "Project Totals", "YTD Sub Totals"];
let ci := Id;
let cx := 0;
let cy := 0;
let cz := 0;
//
// Turn the previous state into a binary mask
for cb in ca do
cx := cx + pow(10, number(cb))
end;
//
// Turn the previous state into a binary mask
for cb in cd do
cy := cy + 1;
if contains(cc, cb) then
cz := cz + pow(10, cy)
end
end;
//
// Subtract them from each other
sw := cz  cx;
// I like to store the result
vlast_action_InvoiceType := sw;
//
Examine each of the possible outcomes with the switch function…
switch sw do
case 10:
(
w := "Deposit on";
b := null;
c := null;
if count(Project.Invoiced[InvoiceNumber = i and isPayments and Id != ci]) then
alert("Not Possible: This invoice number already has a payments record (e1)");
a := null
end;
if ChangeOrderNumber > 0 then
alert("Not Possible: Has nonempty fields (e2)");
a := null
end
)
case 100:
(
w := "Porgress payment on";
a := null;
c := null;
if count(Project.Invoiced[InvoiceNumber = i and isPayments and Id != ci]) then
alert("Not Possible: This invoice number already has a payments record (e3)");
b := null
end;
if ChangeOrderNumber > 0 then
alert("Not Possible: Has nonempty fields (e4)");
b := null
end
)
case 1000:(…)
case 10000:(…)
case 100000:(…)
case 1000000:(…)
case 10:(…)
case 100:(…)
case 1000:(…)
case 10000:(…)
case 100000:(…)
case 1000000:(…)
end;
//
// Gather up the results of the case
let x := [a, b, c, d, e, f];
// set and or override the original user choices
InvoiceType := x;
// post a mirrored copy of the cleaned results to be used next time
vInvoiceTypeFlags := concat(x)

FWIW I will be eager to use this function.
Content aside
 5 yrs agoLast active
 3Replies
 2719Views