获取OData选项集值和名称
我使用的是odata api,现在我在一个实体上有一个属性,它是一个选项选择,如: 属性名为:status 数值为:1、2、3 名称:完成、进展、新 问题是,当我使用postman获取元数据时,我得到的字段“status”的类型都是integer 问题:如何从元数据中获取J选项名称和值,以便得到响应中的值和名称 目前我得到的是:获取OData选项集值和名称,odata,dynamics-crm,microsoft-dynamics,Odata,Dynamics Crm,Microsoft Dynamics,我使用的是odata api,现在我在一个实体上有一个属性,它是一个选项选择,如: 属性名为:status 数值为:1、2、3 名称:完成、进展、新 问题是,当我使用postman获取元数据时,我得到的字段“status”的类型都是integer 问题:如何从元数据中获取J选项名称和值,以便得到响应中的值和名称 目前我得到的是: <Property Name="status" Type="Edm.Int32"> <Annotation Term="Org.ODat
<Property Name="status" Type="Edm.Int32">
<Annotation Term="Org.OData.Core.V1.Description" String="" />
</Property>
但我想得到响应的值和名称 根据这是一个多步骤的过程
请注意,所有示例都使用HTTPGET
首先检索实体的元数据Id。在本例中,我们使用实体“account”:
https://myOrg.crm.dynamics.com/api/data/v8.2/EntityDefinitions?$select=LogicalName,MetadataId&$filter=LogicalName eq‘帐户’
返回:
{
"@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/EntityDefinitions70816501-edb9-4740-a16c-6a5efbc05d84?$select=LogicalName&$expand=Attributes$select=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",
"Attributes@odata.context": "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"
}]
}
然后使用实体和属性的元数据ID进行查询,以获取选项集值:
https://myOrg.crm.dynamics.com/api/data/v8.2/EntityDefinitions70816501-edb9-4740-a16c-6a5efbc05d84/Attributes4e33af09-ba43-4365-a747-c7e4f9992172/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$select=LogicalName&$expand=OptionSet
返回截断为2个值的值:
{
"@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",
"OptionSet@odata.context": "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
}
}
}
}
假设您只需要int值和实体的特定选项集属性的名称,这可以大大简化:
GET [Organization URI]/api/data/v8.2/EntityDefinitions(LogicalName='contact')/Attributes(LogicalName='status')/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$select=LogicalName&$expand=OptionSet($select=Options),GlobalOptionSet($select=Options)
$select=LogicalName只是为了不返回属性的所有其他元数据,$expand=OPTIONATE$select=Options用于本地选项集,$GLOBALOPTIONATE$select=Options用于全局。如果你知道它是什么类型,你可以跳过其他类型,但是如果你把这个逻辑放在一个共享库中,你不是吗?那么,将两者相加不会有什么坏处:
{
@odata.context:http://YourOrg.com/YourInstance/api/data/v8.2/$metadataEntityDefinitions'new_entity'/Attributes/Microsoft.Dynamics.CRM.PicklistAttributeMetadataName、OptionSet、GlobalOptionSet、OptionSetOptions、GlobalOptionSetOptions/$entity,
逻辑名称:new_Family ShortName,
元数据ID:dc11c01f-b6bd-4664-82d0-3a521841c1f5,
OptionSet@odata.context:http://YourOrg.com/YourInstance/api/data/v8.2/$metadataEntityDefinitions'new \'U entity'/Attributesdc11c01f-b6bd-4664-82d0-3a521841c1f5/Microsoft.Dynamics.CRM.PicklistAttributeMetadata/OptionSetOptions/$entity,
OptionSet:null,
全球最佳选择:{
@odata.type:Microsoft.Dynamics.CRM.OptionSetMetadata,
选项:[
{
价值:117280000,
标签:{
本地化标签:[
{
标签:英文值1,
语言代码:1033,
是的,
元数据ID:3cb6bbd5-796f-e111-8cf3-3cd92b023782,
已更改:空
},
{
标签:法国价值1,
语言代码:1036,
IsManaged:错,
元数据ID:d88be67d-4a7d-e411-8890-0050569f1654,
已更改:空
}
],
UserLocalizedLabel:{
标签:英文值1,
语言代码:1033,
是的,
元数据ID:3cb6bbd5-796f-e111-8cf3-3cd92b023782,
已更改:空
}
},
说明:{
本地化标签:[
{
标签:,
语言代码:1033,
是的,
元数据ID:3db6bbd5-796f-e111-8cf3-3cd92b023782,
已更改:空
}
],
UserLocalizedLabel:{
标签:,
语言代码:1033,
是的,
元数据ID:3db6bbd5-796f-e111-8cf3-3cd92b023782,
已更改:空
}
},
颜色:空,
是的,
MetadataId:null,
已更改:空
},
更多
],
元数据ID:dcbbe460-bedb-4985-9a17-2f3dbc637594
}
}
这正是我昨天所做的,我回来回答这个问题,但感谢您的努力和时间:您还可以在末尾使用筛选器查询多个字段,而不是在属性级别进行范围限定:${CRMapiURL}/EntityDefinitionsLogicName='contact'/Attributes/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$select=LogicalName&$expand=OptionSet$select=Options,GlobalOptionSet$select=Options&$filter=LogicalName eq'gendercode'或LogicalName eq'fi eld2'