长时间 运行 异步更新后关闭网络资源

Close web resource after a long running asynchronous update

我使用 WebAPI 进行了一次检索多个 GUID 的调用。我遍历每个结果并相应地更新记录。这一切都是异步完成的。我不希望用户等待所有记录更新,只是想关闭网络资源。 我使用 window.close() 但是,它会中断之前启动的异步更新调用。我怎样才能避免这个?以下是我正在拨打的电话:

window.opener.Xrm.WebApi.online.retrieveMultipleRecords("new_contract", "?$select=new_contractid&$filter=statecode eq 0 and statuscode eq 100000001&$top=5000")
    .then(function(results) {
        for (var i = 0; i < results.entities.length; i++) {
            var new_contractid = results.entities[i]["new_contractid"];
            var processedGuid = new_contractid.replace(/[{}]/g, "");

            var entity = {};
            entity.new_run = new Date(y).toISOString();

            window.opener.Xrm.WebApi.online.updateRecord("new_contract", processedGuid, entity)
                .then(function success(result) {
                    var updatedEntityId = result.id;
                },
                function (error) {
                    Xrm.Utility.alertDialog(error.message);
                });
        }
    }, function (error) {
        Xrm.Utility.alertDialog(error.message);
    });

我正在考虑改用后端的插件。我不确定采用哪种方法,任何输入都会很棒!!

你无法绕过它,你正在关闭正在执行代码的 window。

你最好使用插件。

我会推荐你​​“自定义操作”来实现它,触发并忘记。将所有逻辑移到那里。

It seems we should be thinking of the custom actions as of the “functions”. Those functions can be defined as a mix of workflow steps and plugins – we can pass input parameters into the custom action and retrieve output parameters from the custom action. The reason we can call then “functions” is that, unlike with the workflow/plugins, we can, actually, call those functions from other places – we can call them from javascripts, we can call them from workflows, and we can call them from plugins.

Read more