How to get CDS Optionset value in PowerApps Canvas apps

Follow Debajit’s Power Apps & Dynamics 365 Blog on WordPress.com

Canvas apps have really taken the art of developing pretty neat apps for mobile platforms from a niche set of developers to a wide platform of developers, consultants and business users. And with Microsoft adding features to the Power platform framework every now and then, I don’t find any reason for this to not be in forefront of B2B apps in the days to come.


And yet among so many features provided by the platform, we come across a requirement which is pretty basic and to our surprise we find it’s not a cakewalk like we thought. And one of this requirement is to get the value of a selected option from a CDS option set in Canvas app. And in this blog I am going to explain just that – How to get CDS optionset value in Canvas apps.

As you can see the below screenshot, it is from Account Entity and I have included the “Industry” field which is an optionset.
Below the Industry field, I have a label which shows the value of Industry selected.


image


As you can see, the formula is “ddlIndustry.Selected.Value”. Where ddlIndustry is the name of the dropdown control. As you can see it is printing the text of the selected Item. I tried many ways but unfortunately everytime I ended up getting the Text value. But what if I wanted to get the underlying value instead of text.

image


Well there is way. And surprisingly this is the wonderful JSON() function which you might have already used in so many places for so many purpose but never thought it could actually help you with this requirement also. So let’s see how we can do this.
In the OnChange event of the dropdown control, I use a formula to store the value of the selected item inside a variable

image


And the rest is all to easy. I now use this variable to set the label text.


image


And now when I run, I get the underlying value instead of text.


image

Awesome isn’t it. Such a simple trick which escaped our eyes for so long.
Hope this helps!

You may also like the below posts


Debajit Dutta
(Business Solutions MVP)