Array lookup for table output

Certified Senior Developer

Hey guys.

Just wondering what the best approach is to achieve the below:

Assume I have a form that shows section layouts dependent on the input. In this case the numbers are just used to represent the value of the control.



This would refer to a table such as:




Then depending on what options have been selected overall, the 'Outputs' section only shows the outputs for the numbers that have been selected. The selections from the Output check boxes would then be stored in the record.

An example of this form working would appear like:


I'm guessing that maybe an array used to store the options values selected would work, then an expression rule would some how only provide the choice labels and values for the op_num in the array for the check box/output layout.

Does this all seem possible? Anything I should look out for? Is there possibly a better way that this could be built? I've considered using a matrix table to determine the outputs, however am now researching this 'single output at a time' approach as the matrix table would be massive for my application.

Thanks in advance.

  Discussion posts and replies are publicly visible

  • Hi Andre,

    I think the approach that you suggested should work fine here.  Here's how I would take a look at tackling this problem:

     

    =load(
    local!radioButtonSelected,
    local!checkboxesSelected,
    local!combinedSelected,
    with(
    local!outputValues: rule!getOutputValuesById(local!combinedSelected),
    local!outputLabels: rule!getOutputLabelsById(local!combinedSelected),
    { a!radioButtonField(
    label: "Section 1",
    choiceLabels: {1,2,3},
    choiceValues: {1,2,3},
    value: local!radioButtonSelected,
    saveInto: {
    a!save(local!radioButtonSelected, save!value),
    a!save(local!combinedSelected, save!value),
    a!save(local!checkboxesSelected, {})
    }
    ),
    if(
    local!radioButtonSelected = 3,
    a!checkboxField(
    choiceLabels: {9,10,11},
    choiceValues: {9,10,11},
    value: local!checkboxesSelected,
    saveInto: {
    a!save(local!checkboxesSelected, save!value),
    a!save(local!combinedSelected, append(save!value, 3))
    }
    ),
    {}
    ),
    a!checkboxField(
    choiceLabels: local!outputLabels,
    choiceValues: local!outputValues
    )
    }
    )
    )

    Thanks,

    Lucas

  • You should be able to use a with() variable to accomplish this. If you're querying from the database for the output values, then your with() variable can point directly to the query. Let's say you built the query as rule!queryOutputOptions() and it takes in a list of op_num values. You'll want this query to be null-safe, so that if no op_num values are passed in then it does not execute the query. Then the with() variable could look something like this:

    with(
    local!outputOptions: rule!queryOutputOption(
    opNumList: union(field1values, field2values, field3values)
    ),
    a!checkboxField(
    chocieLabels: local!outputOptions.OP_Labels
    choiceValues: local!outputOptions.OP_Num
    )
    )

    If you don't want to re-query every time then you can query all options first, then do something like this:
    with(
    local!allOptions: rule!queryAllOutputOptions(),
    local!outputOptions: index(local!allOptions, wherecontains(union(field1values, field2values, field3values), local!allOptions.Op_Num), {}),
    a!checkBoxField(...)
    )