cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Resolver II
Resolver II

How to get a Combobox of an OptionSet field in a Form to show the option that corresponds to a text string?

This is really rustling my jimmies. How is this so difficult? *Sigh*

 

I have a Form connected to a CDS entity named 'CDS Entity'. That entity has an OptionSet field called 'Car Types'. That OptionSet has options like "Sedan", "Coupe", "SUV", "Utility", "Semi", "Bus", etc. The Form I added has automatically created a Car_Type_DataCard and a DataCardValue1, which is a ComboBox control and not a Dropdown control.

 

I have a Text variable named varType. It currently holds the text value "Coupe".

 

There are two ways for a user to create a new form. They can press the +New button, or they can press a QuickItem button. If the form is a blank new form, the 'Car Type' combobox is blank. If it is a QuickItem, the 'Car Type' combobox should = varType. If it's neither, then I'm just viewing a record I've selected from a Gallery.

 

When it's a QuickItem, I can't get varType to show up in the combobox using just the combobox. Now I will say I have successfully achieved what I need to do using a workaround that I will include below, but I'm just really pissed that what SHOULD JUST WORK, doesn't work.

 

So as you know there are always at least 2 Form elements for any field in a Form. The Car_Type_DataCard has the property Default. The DataCardValue1 has the properties Items and DefaultSelectedItems. Here are my formulas:

Car_Type_DataCard.Default = 

IfAnd(QuickItem=1,New=1),LookUp(Choices('Car Types'),Name=varType).Value, New=1,Blank(), Gallery.Selected.'Car Type')
DataCardValue1.Items = Choices('Car Types')
DataCardValue1.DefaultSelectedItems = [Parent.Default]
 
I don't get any errors, but the combobox is blank when it shouldn't be. No values show up even though varType has a text value. I've tried 6 LookUp statements in Car_Type_DataCard, and the above is the only one that doesn't give an error. The other statements fail:
LookUp(Choices('Car Types'), Value=varType).Value - Error: incompatible type
LookUp(Choices('Car Types'), Value=varType) - Error: incompatible type
LookUp(Choices('Car Types'), Name=varType).Value - No error, but nothing shows up
LookUp(Choices('Car Types'), Name=varType) - Error: Expected OptionSetValue value
LookUp(Choices('Car Types'), varType in Value) - Error: Expected OptionSetValue value
LookUp(Choices('Car Types'), varType in Name) - Error: Expected OptionSetValue value
 
I've ALSO repeated those 6 statements with the [@''] brackets, as in LookUp(Choices([@'Car Types']), Value=varType), but the results are exactly the same.
 
Now what about DataCardValue1.DefaultSelectedItems? Yes I've ALSO repeated all 12 LookUp statements in DataCardValue1. Results are different and very puzzling. 
LookUp(Choices('Car Types'), Value=varType).Value - Error: incompatible type
LookUp(Choices('Car Types'), Value=varType) - Error: incompatible type
LookUp(Choices('Car Types'), Name=varType).Value - Error: Expected Table value
LookUp(Choices('Car Types'), Name=varType) - No error, but nothing shows up
LookUp(Choices('Car Types'), varType in Value) - It works!!!
LookUp(Choices('Car Types'), varType in Name) - No error, but nothing shows up
 
So it's a different statement that works in the DataCardValue1. But heck, let's keep going. So I need an IF condition that says if it's a QuickItem, then do a LookUp, if it's a blank New item, then leave it blank, else, I need to see the car type of the selected item from a Gallery. So this is what I do:

Car_Type_DataCard.Default = If(New=1Blank(), Gallery.Selected.'Car Type')

DataCardValue1.Items = Choices('Car Types')
DataCardValue1.DefaultSelectedItems = If(And(QuickItem=1,New=1),LookUp(Choices('Car Types'),varType in Value), [Parent.Default])
 
Nope, doesn't work, there's an error. Now that's weird. The LookUp works on its own, and [Parent.Default] works on its own, but put them together in an IF wrapper and they stop working? Ok what if I don't use [Parent.Default] at all? Now let me try:

Car_Type_DataCard.Default = 

DataCardValue1.Items = Choices('Car Types')
DataCardValue1.DefaultSelectedItems = If(And(QuickItem=1,New=1),LookUp(Choices('Car Types'),varType in Value), Blank(), Gallery.Selected.'Car Type')
 
NOOPE. Doesn't work. 
 
__________________________________________________________________
 
Workaround:
I added a dropdown control to the DataCard.

Car_Type_DataCard.Default = If(New=1Blank(), Gallery.Selected.'Car Type')

Dropdown.Items = Choices('Car Types')
Dropdown.Default = If(And(QuickItem=1,ItemState=1),varType,Parent.Default)
DataCardValue1.Items = Choices('Car Types')
DataCardValue1.DefaultSelectedItems = Dropdown.Selected
 
Why does the Form automatically give me a ComboBox if the ComboBox control can't support doing this?? It's so utterly frustrating going through all this mess to find out a Dropdown does just fine!
2 REPLIES 2
Highlighted
Super User II
Super User II

Re: How to get a Combobox of an OptionSet field in a Form to show the option that corresponds to a text string?

That's because a combo box allows more control than a dropdown: a blank default value, multiple selection being the top two for me. 

 

The difference is that in a combo box, the default has to be a table and in a dropdown, just one value

 

Anyways, can you let me what the following results in as the DefaultSelectedItems of the combo box? 

LookUp(Choices('Car Types'), Text(Value) = varType)

 

Let me know and we can make this work and hopefully get rid of your frustration with Power Apps 🙂 

 

---
If you like this reply, please give kudos (Thumbs Up). And if this solves your problem, please mark this reply as a solution by selecting Accept as Solution. This makes it easier for others to find answers to similar questions. 

 

Thanks!

Hardit Bhatia

Blog | Twitter | LinkedIn | Facebook | YouTube  |  Email

 

 

 

Highlighted
Community Support
Community Support

Re: How to get a Combobox of an OptionSet field in a Form to show the option that corresponds to a text string?

Hi @Lexicron ,

 

Please try this in DataCardValue1.DefaultSelectedItems

If(And(QuickItem=1,New=1),LookUp(Choices('Car Types'), varType in Value),LookUp(Choices('Car Types'),Text(Gallery.Selected.'Car Type') in Value))

 

Hope this helps.

Sik

 

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Watch Now

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (7,007)