Canvas Using OptionSets and Lookup Fields

The new options from the CDS and PowerApps canvas applications is to use relationships with 1 to many, or many to 1, however this is natively in the Dynamics 365 CE and now on CDS, but how we use these type of fields; for a technical CRM developer this was using the Code Value for the Optionsets and using the ID Guid for the Lookups, among other parts for the complex object.

The new web API help to resolve or make it more interesting the way we use these 2 objects, let me get into the details on CRM before we get into the PowerApps Canvas App.

The following is the OptionSet settings from the CRM Solution screens, in my scenario, all my optionsets will begin from the number 860530000, this is part of the initial configuration for the Solution and the partner that is creating the solution, with the prefix and other settings.

CRM Field OptionSet - Canvas Using OptionSets and Lookup Fields

Same representation on the CDS, looking at the Entity Fields and selecting the OptionSet and then Click on more options, give me the OptionSet Values I will need.

CDS Field Optionset - Canvas Using OptionSets and Lookup Fields

But in the PowerApps Canvas app, to make it a lot easier I created a collection that will help me with the implementation and also to save the value in back to my custom Entity, like the next code.OptionSets - Canvas Using OptionSets and Lookup Fields

When I implemented the Combo box for the OptionSets in this scenario the Service Type, it will look the following way, where I use the Name as the primary Text to display and to search.

OptionSets Combo 300x179 - Canvas Using OptionSets and Lookup Fields

The Lookup fields are similar to handle, in my scenario I selected the Users Entity, (SystemUsers in CRM), but when using the Connector I notice that there are some user records that I don’t want to display in the Combo box, so the best easy and lazy option I opted was to create a collection with only the Users I want to display, so this is the code I created.

Lookups Sample2 - Canvas Using OptionSets and Lookup Fields

Notice that I created the Values with the Guid ID, I got these values using Jason Lattimer’s CRM REST  Builder, a nice tool that I use a lot in my search in CRM and now also with PowerApps.

The following is the implementation of the PowerApps Combobox.

Lookups Sample2 Combo 300x223 - Canvas Using OptionSets and Lookup Fields

Finally, to Save the record with all the OptionSet and Lookup information I use the “Values”, not the Labels or Names, the Values will automatically identify the relationship in the Lookups and the Labels in the Optionsets.

So I created 2 options to save the record the first one was to use the PowerApps Patch function and the second was to use Flow to pass all the details from the PowerApps app and then save the record.

The following is the PowerApps Patch sample code.

SaveCode 1 - Canvas Using OptionSets and Lookup Fields

Having good control naming convention will give you this easy to follow sample code, where I named all the controls accordingly and you can identify the selected controls and the values that I’m using if you notice the important code in this scenario is the “Selected.Value” part of the controls.

Hope this helps you understand the nuances of these type of fields in CRM and now in CDS.

Next time I will explain the difference between Status Fields and OptionSets, these are not intuitable to understand and follow.

Also the difference between the Lookup field and Customer fields.

 

THIS  BLOG POST HAVE A VIDEO!

 

Join my FREE EMAIL to get more information and videos on Power Platform and Dynamics 365 CE!

https://abesaldana.com/EmailList

Have a blogging or video request? Let me know! (social media links below 😉

* Amazon referral Link:

* Gear list: https://kit.com/AbeSaldana/video-and-podcast-gear

== Follow Us! ==

*Some of the links in this description may be affiliate links, which means I may receive a small commission at NO ADDITIONAL cost to you if you decide to purchase something. But I don’t recommend anything I don’t love so no worries about that! 😉

2 thoughts on “Canvas Using OptionSets and Lookup Fields

Comments are closed.