JavaScript Close web resource after a long running asynchronous update

I make one call that retrieves multiple GUIDs using the WebAPI. I loop through each result and update records accordingly. This is all being done asynchronously. I do not want the user to wait for all the records to update and simply want to close the web resource. I use window.close() however, it is disrupting the asynchronous update calls that were previously initiated. How can I circumvent this? Here are the calls I am making:

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);
    });

I am thinking to use a plugin from the back end instead. I am not sure which approach to take, any input would be great!!

Answer:1

I would recommend you “Custom Action” to achieve it, trigger & forget. Move all the logic in there.

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

Answer:2

I want to open a specific tab of bootstrap 4 from external page link . Page 1: nav.html I want to go from this page one to second page <!DOCTYPE html> <html> <head> <title&...

I want to open a specific tab of bootstrap 4 from external page link . Page 1: nav.html I want to go from this page one to second page <!DOCTYPE html> <html> <head> <title&...

When i run console.log (f ()) i want it returns the data that came from getData (url), but it keeps returning Promise {<pending>}. I thought using await keyword would solve this by making the ...

When i run console.log (f ()) i want it returns the data that came from getData (url), but it keeps returning Promise {<pending>}. I thought using await keyword would solve this by making the ...

Is it possible to mark (change color/size etc) vertex in editable Polygon? var polygon = new google.maps.Polygon({ map:_map, path:path, editable:true, ...

Is it possible to mark (change color/size etc) vertex in editable Polygon? var polygon = new google.maps.Polygon({ map:_map, path:path, editable:true, ...

  1. google maps polygon area
  2. google maps polygon tool
  3. google maps polygon label
  4. google maps polygon api
  5. google maps polygon edit event
  6. google maps polygon creator
  7. google maps polygon coordinates tool
  8. google maps polygon remove point
  9. google maps polygon z index
  10. google maps polygon fill pattern
  11. google maps polygon title
  12. google maps polygon click event
  13. google maps polygon center
  14. google maps polygon to geojson
  15. google maps polygon overlay
  16. google maps polygon infowindow
  17. google maps polygon drawing
  18. google maps polygon get coordinates
  19. google maps polygon get bounds
  20. google maps polygon with hole

I have this ejs file which is to be send as a response using res.render() in node.js <!DOCTYPE html> <html> <head> <title>pilcit</title> </head> <body> &...

I have this ejs file which is to be send as a response using res.render() in node.js <!DOCTYPE html> <html> <head> <title>pilcit</title> </head> <body> &...