How does the WebAPI pass a null value to a Lookup field?
您好,
欢迎来到D365全球支持论坛。
目前来说,在D365中是不允许用户通过webapi来传输或者给lookup字段赋null值的。
如果您想通过webapi来把指定的lookup字段值更改为null,您可以使用"delete"方法。
我在V 9.1.0.6827 Online实例中尝试以下代码来清空潜在客户实体中的货币字段,结果非常成功。
function setNullToLookup(){
var clientURL = Xrm.Page.context.getClientUrl();
var req = new XMLHttpRequest()
req.open("DELETE", encodeURI(clientURL + "/api/data/v9.1/leads(DAFB939B-1FAE-E911-A966-000D3A37FDE9)/transactioncurrencyid/$ref"), true);
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.onreadystatechange = function () {
if (this.readyState == 4 ) {
if (this.status == 204) {
alert("清除lookup字段成功!");
}
else if (this.status == 404) {
alert("要删除的记录不存在!")
}
else {
var error = JSON.parse(this.response).error;
alert("删除lookup字段值失败." + error.message);
}
}
};
req.send();
}
Best Regards,
Leo
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156