Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Unanswered

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

Posted on by 150

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:

example.crm.dynamics.com/.../GlobalOptionSetDefinitions(f4a9de67-1d00-ea11-a811-000d3a33f702)

And this is an example of the response:

{
    "@odata.context": "">example.crm.dynamics.com/.../$metadata,
    "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?

  • cloflyMao Profile Picture
    cloflyMao 25,198 on at
    RE: Query specific value in array from a metadata entity in Dynamics 365

    Hi cjones,

    From contents of following two web pages, I don't think we are able to get Label property in Options collection in GlobalOptionSetDefinitions Web API query directly without iteration.

    http://syednizamsyed.blogspot.com/2016/02/query-metadata-of-global-optionset.html

    https://community.dynamics.com/crm/f/microsoft-dynamics-crm-forum/314670/fetch-only-label-and-value-of-global-option-set-using-web-api-v9/912533

    Instead, you could query Stringmap entity to get value of an option of optionset directly.

    GlobalOptionSetDefinitions:

    8831.JPG

    Stringmap:

    https://example.crm.dynamics.com/api/data/v9.0/stringmaps?$select=attributename,value,attributevalue,objecttypecode&$filter=attributename eq 'cra67_socialmedia' and value eq 'Facebook'

    4812.JPG

    Regards,

    Clofly

  • ishraqiyun77 Profile Picture
    ishraqiyun77 150 on at
    RE: Query specific value in array from a metadata entity in Dynamics 365

    That would still be iterative though. I'm trying to just query the data I need.

  • Pankaj Gogoi Profile Picture
    Pankaj Gogoi 3,177 on at
    RE: Query specific value in array from a metadata entity in Dynamics 365

    Hi Cjones,

    You can deserialize it to an object.

    https://www.newtonsoft.com/json/help/html/DeserializeObject.htm

    You can parse the result into a JsonArray.

    Var result = "Your Json String"

    var jArray = JArray.Parse(result);

    var obj = jArray[0]["Options"]["Label"].....

    Best Regards

    PG

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans