Skip to main content
May 9, 2021
Solved

Choice Labels and choice Values Error

  • May 9, 2021
  • 18 replies
  • 0 views

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:

Best answer by natashan0002

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. 

18 replies

natashan0002
May 9, 2021

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. 

marco.amador
May 10, 2021

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.

May 10, 2021

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".

danny.verb
May 10, 2021

In your database you should try to have a unique primary key, this way your identifiers won't be the same.

May 11, 2021

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.

natashan0002
May 11, 2021

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. 

May 11, 2021

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?

May 11, 2021

it is returning a list of lists.  Use a!flatten() and see if that fixes the issue.

arpitb0001
May 11, 2021

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      labels


Please let me know if it helps you

May 11, 2021

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].

But why did choiceLabels got the correct length but choiceValues didn't?

arpitb0001
May 12, 2021

You are fetching out the data in the choice values and choice labels and you can see colorAvaliable_lotno is same for them due to which its throwing error

For resolving it you can  include all colors in one local vaiable and that variable can be used for choice values and choice labels.

According to it, it will provide us a one value rule!LN_Fetch_colors(local!lotId).data.colorsAvailable[1]. and this is not a best practice to use