简体   繁体   English

从 Dynamics 365 中的元数据实体查询数组中的特定值

[英]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.只是看看有没有办法直接从 Web API URI 查询数组中的这个值。

This is the URI example:这是 URI 示例:

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" .基本上,我有"Value": 799680006这是我想以某种方式添加到 URI 查询参数的内容,这样我最终可以获得"Label": "ABC123"

Any suggestions or is iterating through the array of objects with if Value = x really the only option?是否有任何建议或正在迭代对象数组if Value = x真的是唯一的选择?

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如果您有多个语言包或用于验证自定义或用于 Devops 部署目的,查询元数据就像您使用GlobalOptionSetDefinitions获取所有本地化标签是一回事
  2. Getting the label for the selected picklist value in one of the transaction database record is another purpose为其中一个事务数据库记录中的选定选项列表值获取 label 是另一个目的

If you simply need for second purpose, you can get it by selecting the Formatted value, after adding a header in web api request.如果您只是需要第二个目的,您可以通过选择格式化值,在 web api 请求中添加 header 后获得它。 Read more in my SO answer在我的 SO 答案中阅读更多内容

Another way to inspect the label is using stringmap entity.检查 label 的另一种方法是使用字符串映射实体。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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