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
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.
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 errorFor 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
So is there any way to add a primary key in the automatically generated table?The screenshot which I have provided is of the table which is generated automatically since there is a table "lot" that has a column "colorsAvailable" which can have multiple values.
Hello,
Can you explain how the table is automatically generated?
It is generated by the system or it is already created in the db or it is droped and generated again.
If it is already there, you can change the schema of the table in cloud and then download xsd and map the new column to the cdt.
There is a table called "lot" which has "colorsAvailable" as a column which can have multiple values. So after I verify and publish the cdts to datastore, this table gets generated along with the "lot" table, for keeping each color as a separate row.
ok
Just make the change in the CDT before publishing and it will reflect in the db. (add column and mark it as primary key,auto increament)
The better way is how i explained earlier, using XSD.