I have a local variable local!allProcesses: rule!myGetAllProcesses().data which contains data from a database. The columns are processId, processName, processYear and processQuarter. I now want to have choiceLabels of a drop-down menu which combines processName, processYear and processQuarter. The corresponding choiceValues will be the processIds. Obviously, the following code works only as long as I have only a single row in the database:
choiceLabels: { concat( { local!AllProcesses.processName }, " for ", { local!AllProcesses.processYear }, " Q", { local!AllProcesses.processQuarter } ) }, choiceValues: {local!allProcesses.processId},
Otherwise, for more than one row in the database, the error code will read
Could not display interface. Please check definition and inputs. Interface Definition: Expression evaluation error at function a!dropdownField [line 9]: A dropdown component [label=“Process”] has an invalid value for “choiceValues”. The choiceLabels and choiceValues arrays must be the same length, but choiceLabels was length 1 and choiceValues was length 2.
My question is: How to implement the merging of rows in the most efficient fashion, ideally in the interface itself? I read quite some old threads here in the community, and apparently in the newest Appian version there is a simple solution for it without introducing an expression rule or even a new, derived column in the database. Any guidance would be much appreciated!
Discussion posts and replies are publicly visible
a!foreach( items: local!AllProcesses, expression: concat( fv!item.processName " for ", fv!item.processYear " Q", fv!item.processQuarter ) },
Thanks for the hint. Your code misses a few comas, but otherwise, the solution is to define a local variable as the following (and use it as choiceValues inside the interface).
a!foreach( items: local!AllProcesses, expression: concat( fv!item.processName, " for ", fv!item.processYear, " Q", fv!item.processQuarter ) }
Oh dear, you are right. I missed them.
Yeah, the most efficient way is to store the labels in a local outside of the dropDown field. This way the forEach is not reevaluated on each interaction.