简体   繁体   English

CRM Dynamics 365:如何通过 REST API 获取非全局选项集值元数据?

[英]CRM Dynamics 365: How to get the non global optionset values metadata via REST API?

Dynamics 365 v9.1.动态 365 v9.1。
How to get the non global optionset values metadata via REST API?如何通过 REST API 获取非全局选项集值元数据?

My query: https://mycompany.com/MyCompany/api/data/v9.1/EntityDefinitions(LogicalName='lead')/Attributes(LogicalName='statuscode')我的查询: https://mycompany.com/MyCompany/api/data/v9.1/EntityDefinitions(LogicalName='lead')/Attributes(LogicalName='statuscode')

My C# code:我的 C# 代码:

public static HttpClient CreateCrmHttpClient(string domain, string crmWebApiUrl, string authType, string crmLogin, 
    string crmPassword, Guid? callerId)
{
    var uri = new Uri(crmWebApiUrl);
    var credentialsCache = new CredentialCache
        {{uri, authType, new NetworkCredential(crmLogin, crmPassword, domain)}};

    var handler = new HttpClientHandler {Credentials = credentialsCache};

    var httpClient = new HttpClient(handler) {BaseAddress = uri, Timeout = new TimeSpan(0, 0, 60)};

    httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

    httpClient.DefaultRequestHeaders.Add("OData-MaxVersion", "4.0");
    httpClient.DefaultRequestHeaders.Add("OData-Version", "4.0");
    httpClient.DefaultRequestHeaders.Add("Prefer", "odata.include-annotations=\"*\"");

    if (callerId != null)
    {
        httpClient.DefaultRequestHeaders.Add("MSCRMCallerID", callerId.Value.ToString());
    }
    return httpClient;
}

...

public string RetrieveAttributeMetadata(string entityName, string attributeName)
{
    var httpClient = CrmClientHelper.CreateCrmHttpClient(Domain, CrmWebApiUrl, AuthType, CrmLogin,
        CrmPassword, CallerId);
    var query = $"EntityDefinitions(LogicalName='{entityName}')/Attributes(LogicalName='{attributeName}')";
    var response = httpClient.GetAsync(query).Result;
    return response.Content.ReadAsStringAsync().Result;
}

Below the result, but it doesn't contain OptionSet values metadata.在结果下方,但它不包含 OptionSet 值元数据。 How to get it?:获取方式:

{
"@odata.context": "https://mycompany.com/MyCompany/api/data/v9.1/$metadata#EntityDefinitions('lead')/Attributes/Microsoft.Dynamics.CRM.StatusAttributeMetadata/$entity",
"@odata.type": "#Microsoft.Dynamics.CRM.StatusAttributeMetadata",
"DefaultFormValue": -1,
"AttributeOf": null,
"AttributeType": "Status",
"ColumnNumber": 54,
"DeprecatedVersion": null,
"IntroducedVersion": "5.0.0.0",
"EntityLogicalName": "lead",
"IsCustomAttribute": false,
"IsPrimaryId": false,
"IsValidODataAttribute": true,
"IsPrimaryName": false,
"IsValidForCreate": true,
"IsValidForRead": true,
"IsValidForUpdate": true,
"CanBeSecuredForRead": false,
"CanBeSecuredForCreate": false,
"CanBeSecuredForUpdate": false,
"IsSecured": false,
"IsRetrievable": true,
"IsFilterable": false,
"IsSearchable": false,
"IsManaged": true,
"LinkedAttributeId": null,
"LogicalName": "statuscode",
"IsValidForForm": true,
"IsRequiredForForm": false,
"IsValidForGrid": true,
"SchemaName": "StatusCode",
"ExternalName": null,
"IsLogical": false,
"IsDataSourceSecret": false,
"InheritsFrom": null,
"CreatedOn": "1900-01-01T00:00:00+03:00",
"ModifiedOn": "2022-04-23T06:20:18+03:00",
"SourceType": null,
"AutoNumberFormat": null,
"MetadataId": "ed2b31c0-723f-447b-ac19-7fee763f3c8c",
"HasChanged": null,
"AttributeTypeName": {
"Value": "StatusType"
},
"Description": {
"LocalizedLabels": [
{
"Label": "Выберите состояние интереса.",
"LanguageCode": 1049,
"IsManaged": true,
"MetadataId": "8999f6ca-2241-db11-898a-0007e9e17ebd",
"HasChanged": null
}
],
"UserLocalizedLabel": {
"Label": "Выберите состояние интереса.",
"LanguageCode": 1049,
"IsManaged": true,
"MetadataId": "8999f6ca-2241-db11-898a-0007e9e17ebd",
"HasChanged": null
}
},
"DisplayName": {
"LocalizedLabels": [
{
"Label": "Причина состояния",
"LanguageCode": 1049,
"IsManaged": true,
"MetadataId": "8899f6ca-2241-db11-898a-0007e9e17ebd",
"HasChanged": null
}
],
"UserLocalizedLabel": {
"Label": "Причина состояния",
"LanguageCode": 1049,
"IsManaged": true,
"MetadataId": "8899f6ca-2241-db11-898a-0007e9e17ebd",
"HasChanged": null
}
},
"IsAuditEnabled": {
"Value": true,
"CanBeChanged": true,
"ManagedPropertyLogicalName": "canmodifyauditsettings"
},
"IsGlobalFilterEnabled": {
"Value": false,
"CanBeChanged": true,
"ManagedPropertyLogicalName": "canmodifyglobalfiltersettings"
},
"IsSortableEnabled": {
"Value": false,
"CanBeChanged": true,
"ManagedPropertyLogicalName": "canmodifyissortablesettings"
},
"IsCustomizable": {
"Value": true,
"CanBeChanged": false,
"ManagedPropertyLogicalName": "iscustomizable"
},
"IsRenameable": {
"Value": true,
"CanBeChanged": false,
"ManagedPropertyLogicalName": "isrenameable"
},
"IsValidForAdvancedFind": {
"Value": true,
"CanBeChanged": true,
"ManagedPropertyLogicalName": "canmodifysearchsettings"
},
"RequiredLevel": {
"Value": "None",
"CanBeChanged": true,
"ManagedPropertyLogicalName": "canmodifyrequirementlevelsettings"
},
"CanModifyAdditionalSettings": {
"Value": true,
"CanBeChanged": false,
"ManagedPropertyLogicalName": "canmodifyadditionalsettings"
}
}

You need to expand them, following your query it should be您需要扩展它们,按照您的查询应该是

https://mycompany.com/MyCompany/api/data/v9.1/EntityDefinitions(LogicalName='lead')/Attributes(LogicalName='statuscode')?$expand=OptionSet

the result will contain the optionset values.结果将包含选项集值。

This approach works for optionsets (choice), multiselect optionsets (choices), statecode, statuscode and boolean fields.此方法适用于选项集(选择)、多选选项集(选择)、状态代码、状态代码和 boolean 字段。

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

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