Skip to main content

Notifications

Customer Service forum

How does the WebAPI pass a null value to a Lookup field?

Posted on by 55

How does the WebAPI pass a null value to a Lookup field?

Categories:
  • Suggested answer
    LeoAlt Profile Picture
    LeoAlt 16,329 on at
    RE: 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

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans