Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested answer

One OData request create mutiple records

(0) ShareShare
ReportReport
Posted on by 140

Hi Experts,

 

In 365BC, is it possible to use one OData request to create mutiple records?

For example, I want to use one request to create two sales order lines.

 

Thanks

  • RomRyan Profile Picture
    RomRyan on at
    One OData request create mutiple records
    Hi,
    Did you succeed on this?
     
    I have exposed the native chart of accounts page as an Odata Webservice.
    I need to insert more than one accounts from c# console app that uses the power of odata webservices in business central. I can insert one but when it's come to more than one, the errors and exceptions start popping up.
    here is my extract
    var Context = new BC19.NAV(new Uri(serviceBaseAddress));
    Context.Credentials = CredentialCache.DefaultNetworkCredentials;
    try
    {    
        var coa = new BC19.Chart_of_Accounts
        { 
            No = "111",
            Name = "Banana"                
        };
                   
        Context.AddToChart_of_Accounts(coa);
        Context.SaveChanges();
    }
    This works but if I want to insert more than one am not able. Context.AddToChart_of_Accounts(coa) doesn't allow if coa has more than one account. The issue is the same also in case of the multiple customers.
     
    Kindly assist
  • Denny1986 Profile Picture
    Denny1986 140 on at
    RE: One OData request create mutiple records

    Hi Stefano,

    Because we add some UDFs in the sales order header and sales order lines, so I create two pages for deep insert to use one post to create sales order.

    Now we use API to get sales order successfully, and when use API to create sales order without line, it works,but when I add sales order lines in the request body, it return "error": {

           "code": "Internal_RecordNotFound",

           "message": "The Sales Header does not exist. Identification fields and values: Document Type='Quote',No.='EDI1006'  CorrelationId:  59ed2b89-e61c-4009-ac73-ad241b42c208."

       }

    Below is the pages and request body for you reference? Could you please shed me some lights on it?

    page 70203543 TRCSalesOrder

    {

       APIVersion = 'v1.0';

       Caption = 'salesOrders', Locked = true;

       ChangeTrackingAllowed = true;

       DelayedInsert = true;

       EntityName = 'salesOrder';

       EntitySetName = 'salesOrders';

       ODataKeyFields = "No.";

       PageType = API;

       APIPublisher = 'XXXX';

       APIGroup = 'XXX';

       SourceTable = "Sales Header";

       Extensible = false;

       layout

       {

           area(content)

           {

               repeater(Group)

               {

                   field(id; Id)

                   {

                       ApplicationArea = All;

                   }

                   field("documentType"; "Document Type")

                   {

                       ApplicationArea = All;

                   }

                   field("number"; "No.")

                   {

                       ApplicationArea = All;

                   }

                   field("orderDate"; "Order Date")

                   { ApplicationArea = All; }

                   field("postingDate"; "Posting Date")

                   { ApplicationArea = All; }

                   field("shipmentDate"; "Shipment Date")

                                      .

                                      .

                                      .

                   part(salesOrderLines; 70203542)

                   {

                       ApplicationArea = All;

                       Caption = 'Lines', Locked = true;

                       EntityName = 'salesOrderLine';

                       EntitySetName = 'salesOrderLines';

                       SubPageLink = "Document No." = FIELD("No.");

                   }

               }

           }

       }

       trigger OnInsertRecord(BelowxRec: Boolean): Boolean

       begin

           Insert(true);

           exit(false);

       end;

       trigger OnDeleteRecord(): Boolean

       begin

           Delete(true);

       end;

    }

    page 70203542 TRCSalesOrderLines

    {

       Caption = 'SalesLines';

       PageType = ListPart;

       DelayedInsert = true;

       SourceTable = "Sales Line";

       layout

       {

           area(Content)

           {

               repeater(General)

               {

                   field("documentType"; "Document Type")

                   {

                       ApplicationArea = All;

                   }

                   field("documentNumber"; "Document No.")

                   {

                       ApplicationArea = All;

                   }

                   field("lineNumber"; "Line No.")

                   {

                       ApplicationArea = All;

                   }

                   field("number"; "No.")

                   {

                       ApplicationArea = All;

                   }

                   field("quantity"; Quantity)

                   {

                       ApplicationArea = All;

                   }

                   field("unitPrice"; "Unit Price")

                   {

                       ApplicationArea = All;

                   }

           }

       }

       trigger OnInsertRecord(BelowxRec: Boolean): Boolean

       begin

           Insert(true);

           exit(false);

       end;

       trigger OnDeleteRecord(): Boolean

       begin

           Delete(true);

       end;

    }

    Request Body

    {  

       "number": "EDI1006",

       "sellToCustomerNumber": "10000",

       "documentType": "Order",

       "orderDate": "2020-08-10",

       "postingDate": "2020-08-10",

       "shipmentDate": "2020-08-10",

       "salesOrderLines": [

           {

               "number": "1896-S",

               "quantity": 2,

               "unitPrice": 2

        },

        {

               "number": "1900-S",

               "quantity": 2,

               "unitPrice": 2

        }

       ]

    }

  • Suggested answer
    Stefano Demiliani Profile Picture
    Stefano Demiliani 37,162 Most Valuable Professional on at
    RE: One OData request create mutiple records

    If the exposed entity supports deep insert, yes you can. For the Sales Order this is supported, you can create a sales Order with header and lines by passing a complete JSON object (POST).

  • nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: One OData request create mutiple records

    Moved to D365BC forum.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,489 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans