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

Update Sales Order Lines by Deep insert

(0) ShareShare
ReportReport
Posted on by 140

Hi Experts,

I create a deep insert for in my extension to use one request to create sales order or update sales order.

Now I encounter one problem, I can create sales order with lines successfully.

but when I use request to update the sales order, only the sales header fields are updated, but the lines are updated.

Is anyone can shed me some lights on how to solve this problem? Is it possible to use one request update all lines in the sales order?

Below is the Pages I create and the request I used to update the sales Order.

Thanks

Sales Header

page 70203543 TRCSalesOrderHeaderAPI
{
    APIVersion = 'v1.0';
    Caption = 'salesOrders', Locked = true;
    ChangeTrackingAllowed = true;
    DelayedInsert = true;
    EntityName = 'salesOrder';
    EntitySetName = 'salesOrders';
    ODataKeyFields = "No.";
    PageType = API;
    APIPublisher = 'XXXXX';
    APIGroup = 'XXX';
    SourceTable = "Sales Header";
    Extensible = false;
    Permissions = tabledata "Sales Header" = rimd;

    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; }
                 .
.
.
                part(salesOrderLines; 70203542)
                {
                    ApplicationArea = All;
                    Caption = 'Lines', Locked = true;
                    EntityName = 'salesOrderLine';
                    EntitySetName = 'salesOrderLines';
                    SubPageLink = "Document No." = FIELD("No."), "Document Type" = FIELD("Document Type");
                }           
            }
        }
    }

    trigger OnInsertRecord(BelowxRec: Boolean)Boolean
    begin
        Insert(true);
        Modify(true);
        exit(false);
    end;

    trigger OnDeleteRecord()Boolean
    begin
        Delete(true);
    end;

    trigger OnModifyRecord()Boolean
    var
        SO: Record "Sales Header";
    begin

    end;

}
Sales Lines
page 70203542 TRCSalesOrderLinesAPI
{
    Caption = 'salesOrderLines';
    PageType = ListPart;
    DelayedInsert = true;
    SourceTable = "Sales Line";
    ODataKeyFields = "Document No.";
    AutoSplitKey = true;
    Permissions = tabledata "Sales Line" = rimd;
    layout

    {
        area(Content)
        {
            repeater(General)
            {
                field("documentType"; "Document Type")
                {
                    ApplicationArea = All;
                }
                field("documentNumber"; "Document No.")
                {
                    ApplicationArea = All;

                }
                field("lineNumber"; "Line No.")
                {
                    ApplicationArea = All;

                }
                field("sellToCustomerNumber"; "Sell-to Customer No.")
                {
                    ApplicationArea = All;

                }
                field("type"; Type)
                {
                    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);
        Modify(true);
        exit(false);
    end;

    trigger OnDeleteRecord()Boolean
    begin
        Delete(true);
    end;

    trigger OnModifyRecord()Boolean
    var
        Lines: Record "Sales Line";
    begin
        Lines.Reset();
        Lines.SetRange("Document No.", Rec."Document No.");
        Lines.SetRange("Document Type", Rec."Document Type");
        Lines.SetRange("Line No.", Rec."Line No.");
        if (Lines.FindSet()) then begin
            Lines."Unit Price" := rec."Unit Price";
        end;
        Lines.Modify();
    end;

    var
        InventoryType: Option;

    trigger OnAfterGetCurrRecord()
    var
        item: Record Item;
    begin
        item.Reset();
        if item.Get(rec."No."then
            InventoryType := item.Type;

    end;

}
Request:
Patch:bc110:7048/.../salesOrders('EDI1002')
{
 "orderDate": "2020-08-20",
     "salesOrderLines": [
       {
           "lineNumber": 10000,
           "type": "Item",
           "number": "1896-S",
           "quantity": 3,
           "unitPrice": 6
    }
   ]
I have the same question (0)
  • Suggested answer
    manjusree Profile Picture
    175 on at

    Hi,

    Below link would help you.

    https://www.kauffmann.nl/2020/07/01/deep-insert-with-business-central-apis-part-2/ 

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 3,143

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,694 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,067 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans