简体   繁体   中英

Query specific value in array from a metadata entity in Dynamics 365

I'm trying to avoid iterating through this array, but I imagine that is the only way to handle this. Just seeing if there is a way to directly query this value in the array from the Web API URI.

This is the URI example:

https://example.crm.dynamics.com/api/data/v9.0/GlobalOptionSetDefinitions(f4a9de67-1d00-ea11-a811-000d3a33f702)

And this is an example of the response:

{
    "@odata.context": "https://example.crm.dynamics.com/api/data/v9.0/$metadata#GlobalOptionSetDefinitions/Microsoft.Dynamics.CRM.OptionSetMetadata/$entity",
    "MetadataId": "f4a9de67-1d00-ea11-a811-000d3a33f702",
    "Options": [
        {
            "Value": 799680006,
            "Color": "#0000ff",
            "IsManaged": false,
            "ExternalValue": "",
            "ParentValues": [],
            "MetadataId": null,
            "HasChanged": null,
            "Label": {
                "LocalizedLabels": [
                    {
                        "Label": "ABC123",
                        "LanguageCode": 1033,
                        "IsManaged": false,
                        "MetadataId": "b4eb2c69-b500-ea11-a811-000d3a33fe19",
                        "HasChanged": null
                    }
                ],
                "UserLocalizedLabel": {
                    "Label": "ABC123",
                    "LanguageCode": 1033,
                    "IsManaged": false,
                    "MetadataId": "b4eb2c69-b500-ea11-a811-000d3a33fe19",
                    "HasChanged": null
                }
            }
        }
    ]
}

Basically, I have the "Value": 799680006 which is what I want to somehow add to the URI query parameters, so that I can ultimately get "Label": "ABC123" .

Any suggestions or is iterating through the array of objects with if Value = x really the only option?

Let me clarify two things:

  1. Querying metadata like you are using GlobalOptionSetDefinitions to get all the localized labels if you have multiple language packs or for verifying customizations or for Devops deployment purpose is one thing
  2. Getting the label for the selected picklist value in one of the transaction database record is another purpose

If you simply need for second purpose, you can get it by selecting the Formatted value, after adding a header in web api request. Read more in my SO answer

Another way to inspect the label is using stringmap entity.

https://crmdev.crm.dynamics.com/api/data/v9.1/stringmaps?$filter=objecttypecode eq 'account' and attributename eq 'accountclassificationcode' and attributevalue eq 1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM