简体   繁体   English

我想使用Xrm.WebApi.online.executeMultiple从Dynamics中删除多个CRM记录

[英]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.executeXrm.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.

相关问题 我想使用纯Javascript从MS Dynamics CRM Online 2015添加/检索数据 - I want to add/retrieve data from MS Dynamics CRM Online 2015 using pure Javascript 我想在Dynamics 365 crm中从一种形式重定向到另一种形式 - I want to redirect from one form to another in dynamics 365 crm CRM:用于删除的Xrm Javascript MultiRetrieve - CRM: Xrm Javascript MultiRetrieve for delete 如何从Dynamics 365 CRM在线调用第三方REST服务? - How do I call 3rd party REST service from Dynamics 365 CRM online? Dynamics CRM Sdk.ExecuteMultiple.js响应项均具有相同的ID - Dynamics CRM Sdk.ExecuteMultiple.js Response Items all have same id Javascript-从MS Dynamics CRM Online添加和检索数据 - Javascript - Add and retrieve data from MS Dynamics CRM Online Dynamics CRM:在Eclipse中使用Xrm.Page库 - Dynamics CRM: using Xrm.Page library in Eclipse 在Dynamics 365 CRM上使用Xrm Object将表单设置为只读 - Set form read only using Xrm Object on Dynamics 365 CRM 检索多个记录OData java脚本Microsoft Dynamics CRM - Retrieving Multiple Records OData java Scripts Microsoft Dynamics CRM CRM Dynamics,如何使用一种形式传递值,并使用Xrm.Utility.openEntityForm()在新的Entity(form)中设置值; - CRM Dynamics , How to pass values from one form and set the values in a new Entity(form) using Xrm.Utility.openEntityForm();
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM