[英]Lookup field formatted value from Web API in Microsoft Dynamics CRM is undefined (cannot get formatted value)
I'm using http request to get value of the lookup field, and I can't get it formatted result["_log_postalcode_value"]<\/code> - shows "ff4c33be-5139-e211-bd26-e41f13be0af4", but
result["_log_postalcode_value@OData.Community.Display.V1.FormattedValue"]<\/code> - is undefined.
我正在使用 http 请求来获取查找字段的值,但我无法将其格式化为
result["_log_postalcode_value"]<\/code> - 显示 "ff4c33be-5139-e211-bd26-e41f13be0af4",但
result["_log_postalcode_value@OData.Community.Display.V1.FormattedValue"]<\/code> - 未定义。
I struggling to find out whats wrong in my code, also tried to google but no answers.我努力找出我的代码有什么问题,也试图谷歌但没有答案。 Maybe somebody could help me.也许有人可以帮助我。
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
Could you try CRM Rest builder and see what output you receive. 您可以尝试使用“ CRM Rest”构建器,看看收到了什么输出。 I just tried your usecase in one of my Trail Instance and it worked for me 我只是在一个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();
and here is the output I received 这是我收到的输出
{
@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"
}
You need to use 'expand' property.您需要使用“扩展”属性。
Here is the official document from Microsoft:以下是微软官方文档:
https:\/\/docs.microsoft.com\/en-us\/powerapps\/developer\/data-platform\/webapi\/query-data-web-api#bkmk_lookupProperty<\/a> https:\/\/docs.microsoft.com\/en-us\/powerapps\/developer\/data-platform\/webapi\/query-data-web-api#bkmk_lookupProperty<\/a>
"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.