使用Xrm.WebApi为单值导航属性设置null [英] Setting null for single-valued navigation property using Xrm.WebApi

本文介绍了使用Xrm.WebApi为单值导航属性设置null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在补救过程中,正在对旧的JS网络资源进行重新设计,以进行最新的D365 v9 sdk更改,其中包括客户端脚本API的改进和改进.弃用.

We are in the process of remediation, re-engineering old JS web resources for latest D365 v9 sdk changes w.r.t Client scripting API improvements & deprecation.

使用Xrm.WebApi重写Web api方法时,我们最终遇到了该阻止程序.

When rewriting the web api methods using Xrm.WebApi, we end up with this blocker.

该场景将null设置为查找,并尝试了以下代码:

The scenario is setting null to lookup, and tried the below code:

var data = {
    "abc_relatedentity@odata.bind": null
};

Xrm.WebApi.updateRecord("abc_entity", abc_entityid, data).then(successCallback, errorCallback);

这将引发错误:

'odata.bind'实例或属性注释具有空值.在OData中,'odata.bind'实例或属性注释必须具有非空字符串值."

"The 'odata.bind' instance or property annotation has a null value. In OData, the 'odata.bind' instance or property annotation must have a non-null string value."

这个想法是退出下面的冗余XHR请求代码.但这是我们现在唯一的解决方法(请参考

The idea is to retire the below redundant XHR request code. But this is the only workaround we have now (referring MSDN).

var req = new XMLHttpRequest();
req.open("DELETE", Xrm.Utility.getGlobalContext().getClientUrl() + "/api/data/v9.0/accounts(recordGUID)/account_parent_account/$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) {
        req.onreadystatechange = null;
        if (this.status === 204 || this.status === 1223) {
            //Success - No Return Data - Do Something
        } 
    }
};
req.send();

任何人都面临着&处理了吗?我想念什么吗?

Anybody faced this & handled it? Am I missing something?

推荐答案

您必须使用Delete方法删除查找值 格式如下: /api/data/v8.0/accounts(1DD18913-11CB-E511-80D2-C4346BDC11C1)/primarycontactid/$ ref

You have to use Delete method to remove the lookup value format is as follows: /api/data/v8.0/accounts(1DD18913-11CB-E511-80D2-C4346BDC11C1)/primarycontactid/$ref

这篇关于使用Xrm.WebApi为单值导航属性设置null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆