Search code examples
dynamics-crmdynamics-crm-2016

how to retrieve select option ids and values via the web api


I'm using the api/data/v8.0 API endpoint of a microsoft crm 2016 and I can retrieve and update a specific entity using GET and PATCH on api/data/v8.0/accounts(063e4c86-e7f0-e511-93f7-123456bb6ce7).

That entity has a property called jobtypecode (I can see that on the JSON response of the GET) and on the front end of the CRM the possible values are the following (I retrieved them using dev tools by inspecting that html select):

721874717   Full Time
721874719   Part Time
721874713   Academic
721874714   Other

How can I retrieve those values via the API?

I tried using api/data/v8.0/GlobalOptionSetDefinitions and various combinations of api/data/v8.0/EntityDefinitions but no luck.


Solution

  • You can use EntityDefinitions with the MetadataId of account, add a filter to only get the optionset you want.

    EntityDefinitions(70816501-edb9-4740-a16c-6a5efbc05d84)/Attributes/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$select=LogicalName&$expand=OptionSet,GlobalOptionSet
    

    Source: https://msdn.microsoft.com/en-us/library/mt607522.aspx#bkmk_queryAttributes