我想使用 Xrm.WebApi.online.executeMultiple 从 Dynamics 中删除多条 CRM 记录
I want to delete multiple CRM records from Dynamics with Xrm.WebApi.online.executeMultiple
必须在一次调用中删除多个实体记录,而不是多次回调,因此尝试使用 Xrm.WebApi.online.executeMultiple 删除记录。但是下面编写的代码不起作用。任何帮助将不胜感激。
for (var i=0; i<Checkbox.length; i++)
{
if(Checkbox[i].checked)
{
var id = Checkbox[i].value;// GUID of the record to be deleted
Checkbox[i].checked = false;
DeleteRequests[i]={};
DeleteRequests[i].getMetadata = function(){
return{
boundParameter: undefined,
operationType: 2,
operationName: "Delete",
parameterTypes: {
}
}
}
DeleteRequests[i].etn="cme_entity";
DeleteRequests[i].payload=id;
}
}
window.parent.Xrm.WebApi.online.executeMultiple(DeleteRequests).then(
function (results) {alert("Success");},
function (error) {alert("Failed");});
收到无法处理此操作的奇怪错误。请联系微软。
问题与您构建删除请求对象的方式有关。您需要声明一个函数来设置 getMetadata
函数和所需的 entityReference
对象。
我已经测试了以下解决方案并且有效。
var Sdk = window.Sdk || {};
Sdk.DeleteRequest = function (entityReference) {
this.entityReference = entityReference;
this.getMetadata = function () {
return {
boundParameter: null,
parameterTypes: {},
operationType: 2,
operationName: "Delete",
};
};
};
for (var i = 0; i < Checkbox.length; i++) {
if (Checkbox[i].checked) {
var id = Checkbox[i].value;
Checkbox[i].checked = false;
DeleteRequests[i] = new Sdk.DeleteRequest({ entityType: "account", id: id });
}
}
window.parent.Xrm.WebApi.online.executeMultiple(DeleteRequests).then(
function (results) { alert("Success"); },
function (error) { alert("Failed"); });
不幸的是,Xrm.WebApi.online.execute
和 Xrm.WebApi.online.executeMultiple
的 CRUD 操作没有很好的记录。我写了一篇blog post with some code samples.
重要的部分是将 Sdk.DeleteRequest
函数声明为 window
上的 属性 并使用 new Sdk.DeleteRequest()
实例化请求对象。我进行了一些试验,确定只是像以前那样简单地创建一个请求对象,即使具有正确的属性也不起作用。
希望这对您有所帮助! :)
必须在一次调用中删除多个实体记录,而不是多次回调,因此尝试使用 Xrm.WebApi.online.executeMultiple 删除记录。但是下面编写的代码不起作用。任何帮助将不胜感激。
for (var i=0; i<Checkbox.length; i++)
{
if(Checkbox[i].checked)
{
var id = Checkbox[i].value;// GUID of the record to be deleted
Checkbox[i].checked = false;
DeleteRequests[i]={};
DeleteRequests[i].getMetadata = function(){
return{
boundParameter: undefined,
operationType: 2,
operationName: "Delete",
parameterTypes: {
}
}
}
DeleteRequests[i].etn="cme_entity";
DeleteRequests[i].payload=id;
}
}
window.parent.Xrm.WebApi.online.executeMultiple(DeleteRequests).then(
function (results) {alert("Success");},
function (error) {alert("Failed");});
收到无法处理此操作的奇怪错误。请联系微软。
问题与您构建删除请求对象的方式有关。您需要声明一个函数来设置 getMetadata
函数和所需的 entityReference
对象。
我已经测试了以下解决方案并且有效。
var Sdk = window.Sdk || {};
Sdk.DeleteRequest = function (entityReference) {
this.entityReference = entityReference;
this.getMetadata = function () {
return {
boundParameter: null,
parameterTypes: {},
operationType: 2,
operationName: "Delete",
};
};
};
for (var i = 0; i < Checkbox.length; i++) {
if (Checkbox[i].checked) {
var id = Checkbox[i].value;
Checkbox[i].checked = false;
DeleteRequests[i] = new Sdk.DeleteRequest({ entityType: "account", id: id });
}
}
window.parent.Xrm.WebApi.online.executeMultiple(DeleteRequests).then(
function (results) { alert("Success"); },
function (error) { alert("Failed"); });
不幸的是,Xrm.WebApi.online.execute
和 Xrm.WebApi.online.executeMultiple
的 CRUD 操作没有很好的记录。我写了一篇blog post with some code samples.
重要的部分是将 Sdk.DeleteRequest
函数声明为 window
上的 属性 并使用 new Sdk.DeleteRequest()
实例化请求对象。我进行了一些试验,确定只是像以前那样简单地创建一个请求对象,即使具有正确的属性也不起作用。
希望这对您有所帮助! :)