Hi,
I'm new to Appian and apologies if I missed something really obvious.I'm running into an issue attempting to capture selected choices and their respective labels of an a!multipleDropdownField().
I've declared 4 local variables to hold the list of available choice labels, available choices, selected choice labels and selected choices.
a!localVariables( local!arrChoiceLabels: {"Option1", "Option2", "Option3"}, local!arrChoiceValues: {1, 2, 3}, local!arrSelectedLabel: if( a!isNullOrEmpty(ri!rec.selected), {}, split(ri!rec.selected,";") ), local!arrSelected: if( a!isNullOrEmpty(local!arrSelectedLabel), {}, wherecontains(local!arrSelectedLabel,local!arrChoiceLabels) ),
Then I tried to plug them into the multiple dropdown field, a!multipleDropdownField( choiceLabels: local!arrChoiceLabels, choiceValues: local!arrChoiceValues, label: "Appian Multi Select Dropdown", labelPosition: "ABOVE", value: {local!arrSelected}, saveInto: { local!arrSelected, a!save( local!arrSelectedLabel, index(local!arrChoiceLabels, local!arrSelected, {}) ), a!save( ri!rec.selected, tostring(local!arrSelectedLabel) ) }, searchDisplay: "AUTO", validations: {} ),
The above implementation results in a list of properly selected/deselected labels in arrSelectedLabel list (which flattens fine into the rules input string) but only the first selected element will show in arrSelected list. The drop down itself will reflect that by only highlighting the first selected choice as well. I've also tried replacing the index function with a!forEach - local!arrChoiceLabels[fv!item] loop with the same results.Any ideas where I went wrong?
Thank you!
Discussion posts and replies are publicly visible
a!localVariables( local!arrChoiceLabels: {"Option1", "Option2", "Option3"}, local!arrChoiceValues: {1, 2, 3}, local!arrSelectedLabel: if( a!isNullOrEmpty(ri!rec.selected), {}, split(ri!rec.selected,";") ), local!arrSelected: if( a!isNullOrEmpty(local!arrSelectedLabel), {}, wherecontains(local!arrSelectedLabel,local!arrChoiceLabels) ), { a!multipleDropdownField( choiceLabels: local!arrChoiceLabels, choiceValues: local!arrChoiceValues, label: "Appian Multi Select Dropdown", labelPosition: "ABOVE", value: {local!arrSelected}, saveInto: { local!arrSelected, a!save( local!arrSelectedLabel, index(local!arrChoiceLabels, save!value, {}) ) }, searchDisplay: "AUTO", validations: {} ) } )
Thank you very much for the reply, but the a!save to rule input text field is gone and I need that step. Curiously, when I run a!save of tostring(local!arrSelectedLabel) to a local variable, it executes fine. It breaks when I try to a!save of tostring(local!arrSelectedLabel) to a rule input text field.
Hello. I made some changes to the code. Please refer the code below and let me know if you have any questions.
a!localVariables( local!arrChoiceLabels: {"Option1", "Option2", "Option3"}, local!arrChoiceValues: {1, 2, 3}, local!arrSelectedLabel: if( a!isNullOrEmpty(ri!rec), {}, split(ri!rec,";") ), local!arrSelected: if( a!isNullOrEmpty(local!arrSelectedLabel), {}, wherecontains(local!arrSelectedLabel,local!arrChoiceLabels) ), { a!multipleDropdownField( choiceLabels: local!arrChoiceLabels, choiceValues: local!arrChoiceValues, label: "Appian Multi Select Dropdown", labelPosition: "ABOVE", value: {local!arrSelected}, saveInto: { local!arrSelected, a!save( local!arrSelectedLabel, index(local!arrChoiceLabels, save!value, {}) ), a!save( ri!rec, joinarray(local!arrSelectedLabel, ";") ) }, searchDisplay: "AUTO", validations: {} ) } )
Thank you so very much! Switching from tostring to joinarray worked. Though I'm not clear on why it would work for one but not the other given that both functions return a string and it only breaks when it pertains to ri! not local! variable in an interface, I'll take it.
To answer your question, when the tostring() function is used with a list as a parameter, it converts it to a string and adds one space for each element. See this link https://docs.appian.com/suite/help/24.3/fnc_conversion_tostring.html#convert-a-list-of-variant-to-a-string. So, when you split that string, the result is this: {"Option1", " Option2"}, and that's where it broke. Additionally, since ri!rec is being referenced by two variables (local!arrSelectedLabel, local!arrSelected), the value of those variables gets updated every time ri!rec changes. That's why the dropdown was showing incorrect values.
Thanks again! You are too kind.
Not to throw a monkeywrench into your works but I often recommend against saving multiple values into a single field (i presume "ri!rec" is singular and not an array). The reasoning there is because you end up needing to store the array values "flattened", and to ensure that when they're needed again, that the "unflattening" required is understood (this is tricky because sometimes time and dev teams will have passed).
But if you HAVE to do so, there's a pre-packaged parsing solution that I recommend, called JSON. If you pass an array through a!toJSON, it'll return a flattened string pre-parsed into the JSON format and will be understandable in the future by anywhere that understands JSON. Later you can take that value and pass it back through a!fromJSON and it'll be converted back into an array for you. This saves the hassle and confusion surrounding whether you should use tostring() or joinarray(), and using "split()" later on a separator (and worrying whether the data was accidentally stored with spaces between the items or not).
Thank you for the JSON route, it's always good to have more options, lovely monkey wrenching.