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,
Instead of calling the same rule twice to get the same result, try putting the result in the local variable. Then use this local variable in choicevalues and choiceLabels. This will also help in knowing what is beign returned.
Hello,
As Natasha mentioned in another reply, it would be good to have the result of that rule in a local variable. Since you use it in two places, by referring to the local variable you would be calling the rule only once, instead of twice.
As for the issue you're facing, since choiceLabels and choiceValues expect a list, try to have the expression you currently have between brackets:
choiceLabels: {rule!LN_Fetch_colors(local!lotId).data.colorsAvailable},choiceValues: {rule!LN_Fetch_colors(local!lotId).data.colorsAvailable},
It seems that in your case, the call performed by choiceValues is only retrieving the first value from the rule, not a list with the 2 results.
Is there a reason the expression is returning a datasubset? Could it be updated to return a list of text? I suspect what is happening is choiceLabels and choiceValues are seeing a "list of text lists", thus making the length = 1. Another alternative is to use flatten to reduce the "list of lists".
In your database you should try to have a unique primary key, this way your identifiers won't be the same.
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.
As per the above details,
1. There should be a primary key.2. You can have local!allColours variable which incle the rule which has been used in the choice values as well choice labels like local!allColorDetails:rule!LN_Fetch_colors(local!lotId).data
3. In this way you will able to get all colours details will be collected in the local and then you can use particular local in choice values as well as choice labelsPlease let me know if it helps you
Thank you for your reply. Actually shown table gets created automatically since a table named "lot" has a column with type text with multiple values.
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.
Actually the shown table gets created automatically since a table named "lot" has a column with type text with multiple values. May I know how can I add a primary key to it?
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].