I have created an expression rule, which retrieves all colors based on a "lot number". The rule works fine.
But when I try to use the result on choiceLabels and choiceValues, it gives the error "The choiceLabels and choiceValues arrays must be the same length, but choiceLabels was length 2 and choiceValues was length 1". Both the choicelabel and choicevalue have been passed on the same rule. My database currently has 2 colors for lot number 1.
May I know what did I do wrong?
Code of choice label and choice value:
choiceLabels: rule!LN_Fetch_colors(local!lotId).data.colorsAvailable, choiceValues: rule!LN_Fetch_colors(local!lotId).data.colorsAvailable,
This is the output of the rule:
This is my entry in database:
Discussion posts and replies are publicly visible
Hi,
The rule should actually return two dictionaries. Like the image below. You will need to check your db table schema. Try adding a primary key.
Thank you for you reply. Actually shown table gets created automatically since a table named "lot" has a column with type text with multiple values.
But my problem got solved after I changed rule!LN_Fetch_colors(local!lotId).data.colorsAvailable to rule!LN_Fetch_colors(local!lotId).data.colorsAvailable[1].
But why did choiceLabels got the correct length but choiceValues didn't?
it is returning a list of lists. Use a!flatten() and see if that fixes the issue.
i'm not sure why choiceLabels and choiceValues interpret the list of lists differently, but they do. if you wrap your expression in a!flatten(), you will not have to use [1] to make it work.
Hey! It worked:
a!flatten(rule!LN_Fetch_colors(local!lotId).data.colorsAvailable)
But may I know why choiceLabels was able get correct list but choiceValues didn't?
Apparently those parameters handle inputs of lists of lists slightly differently. Your expression was returning a list of text lists, since each row could have multiple colors. a!flatten converts a "list of text lists" to a "text list" Anyway, glad it worked.