繁体   English   中英

Microsoft Dynamics CRM 中来自 Web API 的查找字段格式化值未定义(无法获取格式化值)

[英]Lookup field formatted value from Web API in Microsoft Dynamics CRM is undefined (cannot get formatted value)

我正在使用 http 请求来获取查找字段的值,但我无法将其格式化为result["_log_postalcode_value"]<\/code> - 显示 "ff4c33be-5139-e211-bd26-e41f13be0af4",但result["_log_postalcode_value@OData.Community.Display.V1.FormattedValue"]<\/code> - 未定义。 我努力找出我的代码有什么问题,也试图谷歌但没有答案。 也许有人可以帮助我。

var req = new XMLHttpRequest();

req.open("GET", window.parent.Xrm.Page.context.getClientUrl() + "/api/data/v8.2/accounts(" + guid + ")?$select=_log_postalcode_value", false);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Prefer", "odata.include-annotations=OData.Community.Display.V1.FormattedValue"); 
req.onreadystatechange = function () {
    if (this.readyState == 4) {          
        req.onreadystatechange = null;   
        if (this.status == 200) {
            var result = JSON.parse(this.response);             
            console.log(result["_log_postalcode_value"]);//shows "ff4c33be-5139-e211-bd26-e41f13be0af4"
            console.log(result["_log_postalcode_value@OData.Community.Display.V1.FormattedValue"]); // shows undefined

您可以尝试使用“ CRM Rest”构建器,看看收到了什么输出。 我只是在一个Trail Instance中尝试了您的用例,它对我有用

var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/accounts(DC86C293-CA4F-E911-A82F-000D3A385A1C)?$select=accountid,_crmp_languagecode_value", false);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function() {
    if (this.readyState === 4) {
        req.onreadystatechange = null;
        if (this.status === 200) {
            var result = JSON.parse(this.response);
            var accountid = result["accountid"];
            var _crmp_languagecode_value = result["_crmp_languagecode_value"];
            var _crmp_languagecode_value_formatted = result["_crmp_languagecode_value@OData.Community.Display.V1.FormattedValue"];
            var _crmp_languagecode_value_lookuplogicalname = result["_crmp_languagecode_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
        } else {
            Xrm.Utility.alertDialog(this.statusText);
        }
    }
};
req.send();

这是我收到的输出

{

    @odata.context:"[ORGURL]/api/data/v8.2/$metadata#accounts(accountid,_crmp_languagecode_value)/$entity",
    @odata.etag:"W/"3139254"",
    accountid:"dc86c293-ca4f-e911-a82f-000d3a385a1c",
    _crmp_languagecode_value@OData.Community.Display.V1.FormattedValue:"FR",
    _crmp_languagecode_value@Microsoft.Dynamics.CRM.associatednavigationproperty:"crmp_languagecode",
    _crmp_languagecode_value@Microsoft.Dynamics.CRM.lookuplogicalname:"crmp_languagecode",
    _crmp_languagecode_value:"78a6bb04-88db-e811-a961-000d3ab42b3b"

}

暂无
暂无

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

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