【发布时间】:2019-12-03 11:38:57
【问题描述】:
我正在为模型驱动的应用程序编写一些客户端自定义,我需要更新 N:N 关系中的条目。我一直在关注文档here。我可以从关系表中读取,但尝试更新条目或创建新条目失败。
N:N 关系在自定义实体 new_lastask 和内置 systemuser 实体之间。为 N:N 关系生成的名称是 new_new_lastask_systemuser。我已设法创建和更新其他记录,并且我知道您需要使用具有确切大小写的Schema name,而不是该字段的name 以及更新查找字段时的@odata.bind 语法,但是我不知道该字段的名称应该是什么。
下面的示例代码尝试查找给定用户的 N:N 记录并将其切换给另一个用户,我已经给出了一个使用 updateRecord 方法的示例,但我也尝试过使用 createRecord 并且我得到了同样的错误。
// taskId is the Guid of the custom task entity, and userId is the guid of the user
var query = "?$filter=new_lastaskid eq " + taskId;
Xrm.WebApi.retrieveMultipleRecords("new_new_lastask_systemuser", query).then(
function success(result) {
for (var i = 0; i < result.entities.length; i++) {
if (result.entities[i].systemuserid===oldUserId) {
// found the offering user, replace them
var data = {
"systemuserid@odata.bind": "/systemusers" + newUserId
}
// try to just change the value of the user attached to the N:N record
Xrm.WebApi.updateRecord(tableName, result.entities[i].new_new_lastask_systemuserid, data).then(
function success(result) {
console.log("Successfully updated");
// perform operations on record update
},
function (error) {
console.log(error.message);
// An error occurred while validating input parameters: Microsoft.OData.ODataException:
// An undeclared property 'systemuserid' which only has property annotations in the payload...
}
);
}
}
},
function (error) {
console.log(error.message);
// handle error conditions
}
);
这是我在尝试使用name 而不是Schema Name 时尝试更新实体上的任何查找字段时遇到的相同错误,因此我认为这可能与字段,所以我尝试了很多变体(SystemUserId、User、SystemUser、systemuser、user、userid),但没有任何效果。
Schema name 应该属于我的 N:N 表上的查找字段,还是我要通过此 API 以错误的方式处理对这些的修改?
【问题讨论】:
标签: dynamics-crm powerapps dynamics-crm-webapi