Looking for PowerObjects? Don’t worry, you’re in the right place! We’ve been part of HCL for several years, and we’ve now taken the final step in our acquisition journey: moving our website to the HCL domain. Nothing else is changing – we are still fanatically focused on Microsoft Business Applications!

HCLTech Microsoft Business Applications Practice Blog

for Dynamics 365, Power Platform and the rest of the Microsoft technology stack


Dynamically Retrieve Color Codes of Options from an Option Set using Web API

Post Author: HCLTech |

When writing applications that we want to adapt to configuration changes, we’ll be querying the metadata. This is best practice when the metadata could change often based on the business requirements, as well as when we have a lot of options. One such useful scenario of reading the metadata is retrieving the color codes of the options in an option set. For instance, consider a Power BI report where users want the ability to filter data based on an option set using the color code. Let’s explore…

To illustrate, let’s use the option set Lead Source on the Lead entity, which has unique color codes defined for each option set. color codes

We can easily retrieve the options from the EntityDefinitions set path by filtering on the attribute using the below format. If the attribute uses a global option set, we can replace the OptionSet in the $expand with GlobalOptionSet:

GET [Organization URI]/api/data/v9.0/EntityDefinitions(LogicalName='lead')/Attributes(LogicalName='leadsourcecode)/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$select=LogicalName&$expand=OptionSet($select=Options)

Here is how the data will look:

color codes

We hope this comes in handy for you the next time you are working with color codes. Be sure to subscribe to our blog for more tips and tricks!

Happy Dynamics 365’ing!

By Joe D365
Joe D365 is a Microsoft Dynamics 365 superhero who runs on pure Dynamics adrenaline. As the face of PowerObjects, Joe D365’s mission is to reveal innovative ways to use Dynamics 365 and bring the application to more businesses and organizations around the world.

PowerObjects Recommends