本文介绍了获取OData选项设置值和名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用odata api,现在我在实体上有一个属性,可以选择:

I am using odata api, now I have an attribute on an entity that is an option select like :

属性名称是:status值是:1, 2, 3名称:done, progress, new

attribute name is : statusvalues are: 1, 2, 3 names: done, progress, new

问题是当我使用邮递员获取元数据时,对于字段状态",我所获得的全部是其类型整数.

the thing is when I am using postman to fetch metadata and all I get for the fields 'status' its that its type integer.

问题我如何从元数据中获取选项名称和值,以便获得响应中的值和名称?

Question how do I fetchj option names and values from metadata so I get values and names in response ?

当前,我得到了:

  <Property Name="status" Type="Edm.Int32">
     <Annotation Term="Org.OData.Core.V1.Description" String="" />
  </Property>

但是我想在响应中获取值和名称吗?

But I want to get the value and names on response ?

推荐答案

根据本文这是一个多步骤过程.

According to this article this is a multi-step process.

请注意,所有示例均使用HTTP GET.

Please note that all the examples use HTTP GET.

首先获取实体的MetaData ID(在此示例中,我们使用的是实体帐户"):https://myOrg.crm.dynamics.com/api/data/v8.2/EntityDefinitions?$select=LogicalName,MetadataId&$filter=LogicalName eq 'account'

First retrieve the entity's MetaData Id (for this example we're using the entity 'account'):https://myOrg.crm.dynamics.com/api/data/v8.2/EntityDefinitions?$select=LogicalName,MetadataId&$filter=LogicalName eq 'account'

返回:

{
    "@odata.context": "https://myOrg.crm.dynamics.com/api/data/v8.2/$metadata#EntityDefinitions(LogicalName,MetadataId)",
    "value": [{
        "LogicalName": "account",
        "MetadataId": "70816501-edb9-4740-a16c-6a5efbc05d84"
    }]
}

然后检索属性的MetaDataId(在本示例中,我们使用选项集"customertypecode"):https://myOrg.crm.dynamics.com/api/data/v8.2/EntityDefinitions(70816501-edb9-4740-a16c-6a5efbc05d84)?$select=LogicalName&$expand=Attributes($select=LogicalName;$filter=LogicalName eq 'customertypecode')

Then retrieve the attribute's MetaDataId (in this example we're using the option set 'customertypecode'):https://myOrg.crm.dynamics.com/api/data/v8.2/EntityDefinitions(70816501-edb9-4740-a16c-6a5efbc05d84)?$select=LogicalName&$expand=Attributes($select=LogicalName;$filter=LogicalName eq 'customertypecode')

返回:

{
    "@odata.context": "https://myOrg.crm.dynamics.com/api/data/v8.2/$metadata#EntityDefinitions(LogicalName,Attributes(LogicalName))/$entity",
    "LogicalName": "account",
    "MetadataId": "70816501-edb9-4740-a16c-6a5efbc05d84",
    "[email protected]": "https://myOrg.crm.dynamics.com/api/data/v8.2/$metadata#EntityDefinitions(70816501-edb9-4740-a16c-6a5efbc05d84)/Attributes(LogicalName)",
    "Attributes": [{
        "@odata.type": "#Microsoft.Dynamics.CRM.PicklistAttributeMetadata",
        "LogicalName": "customertypecode",
        "MetadataId": "4e33af09-ba43-4365-a747-c7e4f9992172"
    }]
}

然后使用实体和属性的MetadataIds查询以获取选项集值:https://myOrg.crm.dynamics.com/api/data/v8.2/EntityDefinitions(70816501-edb9-4740-a16c-6a5efbc05d84)/Attributes(4e33af09-ba43-4365-a747-c7e4f9992172)/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$select=LogicalName&$expand=OptionSet

Then query with the entity's and attribute's MetadataIds to get the option set values:https://myOrg.crm.dynamics.com/api/data/v8.2/EntityDefinitions(70816501-edb9-4740-a16c-6a5efbc05d84)/Attributes(4e33af09-ba43-4365-a747-c7e4f9992172)/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$select=LogicalName&$expand=OptionSet

返回值(截断为2个值):

Returns (truncated at 2 values):

{
    "@odata.context": "https://myOrg.crm.dynamics.com/api/data/v8.2/$metadata#EntityDefinitions(70816501-edb9-4740-a16c-6a5efbc05d84)/Attributes/Microsoft.Dynamics.CRM.PicklistAttributeMetadata(LogicalName,OptionSet)/$entity",
    "LogicalName": "customertypecode",
    "MetadataId": "4e33af09-ba43-4365-a747-c7e4f9992172",
    "[email protected]": "https://myOrg.crm.dynamics.com/api/data/v8.2/$metadata#EntityDefinitions(70816501-edb9-4740-a16c-6a5efbc05d84)/Attributes(4e33af09-ba43-4365-a747-c7e4f9992172)/Microsoft.Dynamics.CRM.PicklistAttributeMetadata/OptionSet/$entity",
    "OptionSet": {
        "MetadataId": "3629e642-b895-41ab-8f1d-ea5bfa30e992",
        "HasChanged": null,
        "IsCustomOptionSet": false,
        "IsGlobal": false,
        "IsManaged": true,
        "Name": "account_customertypecode",
        "ExternalTypeName": null,
        "OptionSetType": "Picklist",
        "IntroducedVersion": "5.0.0.0",
        "Description": {
            "LocalizedLabels": [{
                "Label": "Type of the account.",
                "LanguageCode": 1033,
                "IsManaged": true,
                "MetadataId": "73f68e38-c78d-48a5-80cb-bee895baab2b",
                "HasChanged": null
            }],
            "UserLocalizedLabel": {
                "Label": "Type of the account.",
                "LanguageCode": 1033,
                "IsManaged": true,
                "MetadataId": "73f68e38-c78d-48a5-80cb-bee895baab2b",
                "HasChanged": null
            }
        },
        "DisplayName": {
            "LocalizedLabels": [{
                "Label": "Relationship Type",
                "LanguageCode": 1033,
                "IsManaged": true,
                "MetadataId": "e5d47366-fd09-41e6-96a1-cbfdd113b932",
                "HasChanged": null
            }],
            "UserLocalizedLabel": {
                "Label": "Relationship Type",
                "LanguageCode": 1033,
                "IsManaged": true,
                "MetadataId": "e5d47366-fd09-41e6-96a1-cbfdd113b932",
                "HasChanged": null
            }
        },
        "IsCustomizable": {
            "Value": true,
            "CanBeChanged": false,
            "ManagedPropertyLogicalName": "iscustomizable"
        },
        "Options": [{
            "Value": 1,
            "Color": null,
            "IsManaged": true,
            "ExternalValue": null,
            "MetadataId": null,
            "HasChanged": null,
            "Label": {
                "LocalizedLabels": [{
                    "Label": "Competitor",
                    "LanguageCode": 1033,
                    "IsManaged": true,
                    "MetadataId": "6c54c2fa-2241-db11-898a-0007e9e17ebd",
                    "HasChanged": null
                }],
                "UserLocalizedLabel": {
                    "Label": "Competitor",
                    "LanguageCode": 1033,
                    "IsManaged": true,
                    "MetadataId": "6c54c2fa-2241-db11-898a-0007e9e17ebd",
                    "HasChanged": null
                }
            },
            "Description": {
                "LocalizedLabels": [],
                "UserLocalizedLabel": null
            }
        },
        {
            "Value": 2,
            "Color": null,
            "IsManaged": true,
            "ExternalValue": null,
            "MetadataId": null,
            "HasChanged": null,
            "Label": {
                "LocalizedLabels": [{
                    "Label": "Consultant",
                    "LanguageCode": 1033,
                    "IsManaged": true,
                    "MetadataId": "6e54c2fa-2241-db11-898a-0007e9e17ebd",
                    "HasChanged": null
                }],
                "UserLocalizedLabel": {
                    "Label": "Consultant",
                    "LanguageCode": 1033,
                    "IsManaged": true,
                    "MetadataId": "6e54c2fa-2241-db11-898a-0007e9e17ebd",
                    "HasChanged": null
                }
            },
            "Description": {
                "LocalizedLabels": [],
                "UserLocalizedLabel": null
            }
        }
    }
}

这篇关于获取OData选项设置值和名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 08:32