[英]I want to delete multiple CRM records from Dynamics with Xrm.WebApi.online.executeMultiple
Multiple entity records have to be deleted in one call instead of multiple callbacks so trying to use Xrm.WebApi.online.executeMultiple to delete records. 必须在一个调用中删除多个实体记录,而不是多个回调,因此尝试使用Xrm.WebApi.online.executeMultiple删除记录。 but the code written below is not working. 但是下面编写的代码不起作用。 Any help will be appreciated. 任何帮助将不胜感激。
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");});
Getting weird error that this operation could not be processed. 出现奇怪的错误,表明此操作无法处理。 Please contact Microsoft. 请与Microsoft联系。
The issue has to do with how you are constructing the delete request objects. 问题与您如何构造删除请求对象有关。 You need to declare a function that sets up the getMetadata
function and the required entityReference
object. 您需要声明一个用于设置getMetadata
函数和必需的entityReference
对象的函数。
I've tested the below solution and it works. 我已经测试了以下解决方案,并且可以正常工作。
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"); });
Unfortunately CRUD operations with Xrm.WebApi.online.execute
and Xrm.WebApi.online.executeMultiple
are not very well documented. 不幸的是, Xrm.WebApi.online.execute
和Xrm.WebApi.online.executeMultiple
CRUD操作Xrm.WebApi.online.execute
Xrm.WebApi.online.executeMultiple
不够好。 I've written a blog post with some code samples . 我已经写了一篇博客文章,其中包含一些代码示例 。
The important parts are the declaration of the Sdk.DeleteRequest
function as a property on window
and instantiating a request object using new Sdk.DeleteRequest()
. 重要的部分是将Sdk.DeleteRequest
函数声明为window
上的属性,并使用new Sdk.DeleteRequest()
实例化请求对象。 I experimented a little and determined that just simply creating a request object like you were doing before, even with the right attributes does not work either. 我做了一些试验,并确定只是像以前一样简单地创建一个请求对象,即使具有正确的属性也不起作用。
Hope this helps! 希望这可以帮助! :) :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.