Retrieve OptionSet from Dynamics Web API MetaData

1k Views Asked by At

I'm trying to retrieve the option set values (localized labels and integer Ids) for a specific field on a specific entity. Below is the code that I am using, but every time I execute it, it brings back ALL optionsets that are currently in my system (about 800+) and I don't want to do that.

EntityDefinitions(LogicalName='#MY_ENTITY#')/Attributes/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$select=LogicalName&$filter=LogicalName eq '#MY_ENTITY_ATTRIBUTE#'&$expand=OptionSet

2

There are 2 best solutions below

0
viktorh On

maybe this can help,

/api/data/v9.1/ENTITY(guid OR Filter)?$select=ATTRIBUTE1,ATTRIBUTE2

include header:

{
  "Prefer": "odata.include-annotations=OData.Community.Display.V1.FormattedValue"
}

this gives us a response like this:

{
        "[email protected]": "Person",
        "ATTRIBUTE1": 1,
        "[email protected]": "Company",
        "ATTRIBUTE2": 2
}
0
BramV On

I'm using the stringmap entity to retrieve the optionsets.

This represents the optionsets as a simple table on which you can filter in the query

For example by calling: /stringmaps?$filter=(objecttypecode eq 'contacts') you get only the optionsets which are use in the contact entity. You can also filter on attribute name, the option value (field value) or option id (field attributevalue).