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.
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:
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!