web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

My Browser freeze when i try to update 500 records using batch request

(0) ShareShare
ReportReport
Posted on by 365

I trying to bulk update 500 records using batch request through a javascript code my problem is when i trigger my script my browser freeze is there any way i can solve this problem

here is my code:

var data = [];
    data.push('--batch_123456');
    data.push('Content-Type: multipart/mixed;boundary=changeset_BBB456');
    data.push('');
    parent.Xrm.WebApi.retrieveMultipleRecords("opportunityproduct", query).then(
        function success(result) {
            for (var i = 0; i < result.entities.length; i++) {
                var var1;
                var var2;
                var var3;
                var remise = 0;
                var var0 = remise / 100;
                var1 = 1 - var0;
                var prixDachat = 0;
                var tauxDeMarge = 0;
                tauxDeMarge = tauxDeMarge / 100;
                var2 = 1 + tauxDeMarge;
                var tauxDevise = 0;
                var fraisDapproche = 0;
                var s = result.entities[i].cbi_fieldsconcatenation;
                var match = s.split(',')
                if (returnValue.remise) {
                    remise = parseInt(returnValue.remise, 10);
                    var var0 = remise / 100;
                    var1 = 1 - var0;
                } else {
                    if (match[1]) {
                        remise = parseInt(match[1], 10);
                        var var0 = remise / 100;
                        var1 = 1 - var0;
                    }
                }

                if (returnValue.tauxdemarge) {
                    tauxDeMarge = parseInt(returnValue.tauxdemarge, 10);
                    var var4 = tauxDeMarge / 100;
                    var2 = 1 + var4;
                } else {
                    if (match[3]) {
                        tauxDeMarge = parseInt(match[3], 10);
                        var var4 = tauxDeMarge / 100;
                        var2 = 1 + var4;
                    }
                }
                if (returnValue.tauxdevise) {
                    tauxDevise = parseInt(returnValue.tauxdevise, 10);
                } else {
                    if (match[2]) {
                        tauxDevise = parseInt(match[2], 10);
                    }
                }
                if (returnValue.fraisdapproche) {
                    fraisDapproche = parseInt(returnValue.fraisdapproche, 10);
                } else {
                    if (match[4]) {
                        fraisDapproche = parseInt(match[4], 10);
                    }
                }
                if (match[0]) {
                    prixDachat = parseInt(match[0], 10);

                }

                var3 = (prixDachat * var1 * var2) + fraisDapproche;
                //first request
                data.push('--changeset_BBB456');
                data.push('Content-Type:application/http');
                data.push('Content-Transfer-Encoding:binary');
                data.push('Content-ID:' + i);
                data.push('');
                data.push('PATCH ' + parent.Xrm.Page.context.getClientUrl() + '/api/data/v9.1/opportunityproducts(' + result.entities[i].opportunityproductid + ') HTTP/1.1');
                data.push('Content-Type:application/json;type=entry');
                data.push('');
                data.push('{ "cbi_remise":' + remise + ',"cbi_fraisdapproche":' + fraisDapproche + ',"cbi_tauxdemarge":' + tauxDeMarge + ',"cbi_tauxdechange":' + tauxDevise + ',"priceperunit":' + var3 + '}');
                //end of changeset
            }
            data.push('--changeset_BBB456--');
            //end of batch
            data.push('--batch_123456--');
            var payload = data.join('\r\n');
            $.ajax({
                method: 'PATCH',
                url: parent.Xrm.Page.context.getClientUrl() + '/api/data/v9.1/$batch',
                headers: {
                    'Content-Type': 'multipart/mixed;boundary=batch_123456',
                    'Accept': 'application/json',
                    'Odata-MaxVersion': '4.0',
                    'Odata-Version': '4.0',
                },

                data: payload,
                async: false,
                success: function(data, textStatus, xhr) {
                   Xrm.Page.getControl("opportunityproductsGrid").refresh();
                },
                error: function(xhr, data, textStatus, errorThrown) {
                    alert(data, textStatus + " " + errorThrown);
                }
            });
        },
        function(error) {
            console.log(error.message);
            // handle error conditions
        }

    );

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Ben Thompson Profile Picture
    6,350 on at

    You have the batch query running as  async: false so the browser waits for the response before moving to the next task...

  • Anas Rafik Profile Picture
    365 on at

    Yes because i need to make the user update records in real time then refresh my grid is there any other way i can solve the problem without changing the request to asyncronous

  • Verified answer
    Ben Thompson Profile Picture
    6,350 on at

    Not really because you're asking the system to process the batch request now and that batch request could in theory contain anything so it grabs whatever resources are available and uses them to complete the request.

    It's the same as when you are publishing / removing a solution (I've been doing a lot of that today to get a demo instance into a usable state for a PoC) where the system will refuse to handle other requests until the solution removal / batch process has been completed.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans