web
You’re offline. This is a read only version of the page.
close
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

I have the same question (0)
  • nmaenpaa Profile Picture
    101,162 Moderator on at

    Moved to D365BC forum.

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

    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).

  • Denny1986 Profile Picture
    140 on at

    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

        }

       ]

    }

  • RomRyan Profile Picture
    on at
    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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,066

#2
YUN ZHU Profile Picture

YUN ZHU 658 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 595

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans