12

I am quite new to Dynamics CRM. I am building an app which should update entity in Dynamics CRM. I can update simple types without any issues. Now the situation is, I have declared some custom Option Sets in Contact entity.

Is there any way to retrieve all the possible OptionSet values (text and value) so that my app can look for appropriate value and set it in the payload it is generating?

I can not find any endpoint in WebAPI as well as XRMServices/2011/OrganizationData.svc. Any help would be really awesome.

5 Answers 5

20

You can use either the Web API or Organisation Service to retrieve The metadata and data models in Microsoft Dynamics CRM. Check out the sub articles of that one for specific examples and details.

Web API example Querying EntityMetadata attributes.

The following query will return only the PicklistAttributeMetadata attributes and will include the LogicalName as well as expanding the OptionSet and GlobalOptionSet collection-valued navigation properties.

GET [Organization URI]/api/data/v8.1/EntityDefinitions(70816501-edb9-4740-a16c-6a5efbc05d84)/Attributes/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$select=LogicalName&$expand=OptionSet,GlobalOptionSet
3
  • This is for a Two Options (AttributeType === 'Boolean'): Microsoft.Dynamics.CRM.BooleanAttributeMetadata Commented Sep 29, 2017 at 10:55
  • Hello, I am also new to CRM and have a similar use case. 1. The above Query gives me Global Optoinset data but not for Optionsets defined at Entity level 2. Even for Global Optionsets, I did not get all the data. 3. What does the GUID - 70816501-edb9-4740-a16c-6a5efbc05d84 specify, is it a Universal value? If not, Where can I get the corresponding value. Any link detailing this further is highly appreciated.
    – SKocheta
    Commented Mar 5, 2018 at 11:20
  • 1
    Update : Was able to get this via: [Organization URI]/api/data/v8.2/EntityDefinitions(LogicalName='[Entity Name]')/Attributes(LogicalName='[Your Field Name Which uses OptionSet]')/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$select=LogicalName&$expand=OptionSet($select=Options),GlobalOptionSet($select=Options)
    – SKocheta
    Commented Mar 5, 2018 at 11:45
2

Another option would be to get the data via the StringMap entity:

[Organization URI]/api/data/v9.1/stringmaps?fetchXml=<fetch><entity name='stringmap'><filter><condition attribute='objecttypecodename' operator='in'><value>account</value><value>opportunity</value></condition></filter></entity></fetch>

Will provide data that looks like this:

{
"@odata.etag": "W/\"406742363\"",
"value": "Open",
"attributename": "statecode",
"langid": 1033,
"objecttypecode": "opportunity",
"attributevalue": 0,
"stringmapid": "0fe09734-3914-e711-80ef-e0071b6a7121",
"organizationid": "f95718b2-5c63-46df-adc3-c3b546cf686a",
"displayorder": 1
},
{
"@odata.etag": "W/\"406742364\"",
"value": "Won",
"attributename": "statecode",
"langid": 1033,
"objecttypecode": "opportunity",
"attributevalue": 1,
"stringmapid": "10e09734-3914-e711-80ef-e0071b6a7121",
"organizationid": "f95718b2-5c63-46df-adc3-c3b546cf686a",
"displayorder": 2
},

Simpler query:

[Organization URI]/api/data/v9.1/stringmaps?$filter=objecttypecode eq 'account' or objecttypecode eq 'opportunity'
1
  • I have tried with above example and it is working. Thanks for helping.
    – Sapnandu
    Commented Jul 31, 2023 at 17:20
1

Use below code to get specific option set for specific entity: (replace EntityLogicalName and AttributeLogicalName with your input params)

GET [Organization URI]/api/data/v9.1/EntityDefinitions(LogicalName='EntityLogicalName')/Attributes/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$select=LogicalName&$expand=OptionSet($select=Options),GlobalOptionSet($select=Options)&$filter=LogicalName eq 'AttributeLogicalName'
1

If your options are global, this is the easiest way to get all options:

/api/data/v9.1/GlobalOptionSetDefinitions(Name='new_category')
1

First, you need the attribute name and type, which you can find here:

/api/data/v9.1/EntityDefinitions(LogicalName='myEntity')?$select=LogicalName&$expand=Attributes($select=LogicalName)

Replace myEntity above with your entity name. The resulting page lists all the attributes that make up your entity. Locate the desired option set attribute and note its logical name and type.

Armed with that information, go here:

/api/data/v9.1/EntityDefinitions(LogicalName='myEntity')/Attributes(LogicalName='myAttribute')/Microsoft.Dynamics.CRM.MultiSelectPicklistAttributeMetadata?$select=LogicalName&$expand=OptionSet($select=Options),GlobalOptionSet($select=Options)

Replace myEntity and myAttribute with your entity name and attribute name, respectively. If your attribute type is not MultiSelectPicklistAttributeMetadata, replace that with the correct type that was found on the previous page. This returns a list of all the possible values for the option set (both text and numeric values).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.