Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Create Record using Batch Web API

Posted on by 285

Hi All,

I am trying to create multiple  Records in custom entity using Batch Execute. My Batch is executing but records are not created in entity. I am not able to identify what wrong I am doing.

2114378.Capture.PNG

Thank you in advance

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Create Record using Batch Web API

    Hi Rushikesh ,

    I am facing the same issue did you get the solution? If yes please help me also.

    Thanks

    Ankit

  • Rushikesh Bhujbal Profile Picture
    Rushikesh Bhujbal 285 on at
    RE: Create Record using Batch Web API

    Yes.. I am getting 200 OK as response. but not able to see expected result

  • Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: Create Record using Batch Web API

    Have you tried debugging the code?

  • Rushikesh Bhujbal Profile Picture
    Rushikesh Bhujbal 285 on at
    RE: Create Record using Batch Web API

    function testBatch() {

       var data = [];

       data.push('--batch_123456');

       data.push('Content-Type: multipart/mixed;boundary=changeset_BBB456');

       data.push('');

       data.push('--changeset_BBB456');

       data.push('Content-Type:application/http');

       data.push('Content-Transfer-Encoding:binary');

       data.push('Content-ID:1');

       data.push('');

       data.push('POST ' + window.parent.Xrm.Page.context.getClientUrl() + '/api/data/v8.2/rnct_dailyfooddeliveries HTTP/1.1');

       data.push('Content-Type:application/json;type=entry');

       data.push('');

       data.push('{"rnct_name":"199"}');

       data.push('--changeset_BBB456');

       //data.push('--batch_123456');

       data.push('Content-Type:application/http');

       data.push('Content-Transfer-Encoding:binary');

       data.push('Content-ID:2');

       data.push('');

       data.push('POST ' + window.parent.Xrm.Page.context.getClientUrl() + '/api/data/v8.2/rnct_dailyfooddeliveries HTTP/1.1');

       data.push('Content-Type:application/json;type=entry');

       data.push('');

       data.push('{"rnct_name":"199"}');

       data.push('--changeset_BBB456--');

       data.push('--batch_123456--');

       var payload = data.join('\r\n');

       var req = new XMLHttpRequest();

       req.open("POST", window.parent.Xrm.Page.context.getClientUrl() + "/api/data/v8.2/$batch", true);

       req.setRequestHeader("Content-Type", 'multipart/mixed;boundary=--batch_123456');

       req.setRequestHeader("Accept", "application/json");

       req.setRequestHeader("OData-MaxVersion", "4.0");

       req.setRequestHeader("OData-Version", "4.0");

       //  req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");

       req.onreadystatechange = function () {

           if (this.readyState === 4) {

               console.log(this.responseText);

           }

       }

       req.send(payload);

    }

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: Create Record using Batch Web API

    Hi Rushikesh,

    Can you please share the full code?

    Also, see the link below and make sure that you are using the same code.

    community.dynamics.com/.../web-api-bulk-operations

  • Rushikesh Bhujbal Profile Picture
    Rushikesh Bhujbal 285 on at
    RE: Create Record using Batch Web API

    I have used this headers

    req.open("POST", window.parent.Xrm.Page.context.getClientUrl() + "/api/data/v8.1/$batch", true);

       req.setRequestHeader("Content-Type", 'multipart/mixed;boundary=--batch_123456');

       req.setRequestHeader("Accept", "application/json");

       req.setRequestHeader("OData-MaxVersion", "4.0");

       req.setRequestHeader("OData-Version", "4.0");

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans