Skip to main content
Community site session details

Community site session details

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

Modify other line in form

(0) ShareShare
ReportReport
Posted on by 555

Hi experts,

In Business Central cloud, I would like the sales order to work this way: When entering a line, it automatically makes a new line below with another item number. That works fine.

When the user change the Quantity field in the first line, it is also automatically updates the other line, it created automatically before. The two lines must have the same value in Quantity.

The problem is that when the Quantity field is changed in the first line, the second line is changed, BUT it is not visible on the screen. And after that, the second line is locked somehow so it is not possible to change it. The cursor cannot get into the fields in that line.

I have all my code in a table extension for Sales Line in the trigger OnAfterModify. Here is the code:

    trigger OnAfterModify()
    begin
        if ... then begin
            CreateDepositLines(Rec);
        end;
    end;
    local procedure CreateDepositLines(SalesLine : Record "Sales Line")
    var
        Item: Record Item;
        DepositType: Record "Deposit Type";
        DepositSalesLine: Record "Sales Line";
    begin
        Item.GET("No.");

        DepositSalesLine.Init();
        DepositSalesLine.Validate("Document Type", SalesLine."Document Type");
        DepositSalesLine.Validate("Document No.", SalesLine."Document No.");
        DepositSalesLine.Validate("Sell-to Customer No.", SalesLine."Sell-to Customer No.");
        DepositSalesLine.Validate(Type, DepositSalesLine.Type::Item);
        DepositSalesLine.Validate("No.",DepositType."Item No.");
        DepositSalesLine.Validate("Line No.",SalesLine."Line No." + 1000);
        DepositSalesLine.Validate(Description, 'Well...');
        DepositSalesLine.Validate(Quantity, SalesLine.Quantity);
        DepositSalesLine.Validate("Location Code", '');
        DepositSalesLine.Insert(true);
        Commit();
    end;
  • Morten Steengaard Profile Picture
    555 on at
    RE: Modify other line in form

    Hi Inge,

    You are absolutely correct.

    Best regards,

    Morten

  • Suggested answer
    Inge M. Bruvik Profile Picture
    1,029 Moderator on at
    RE: Modify other line in form

    Hi Morten!

    Good that you got it working.

    You are probably aware of this but the downside of putting your code in a page trigger is that it will not be triggered if your sales lines are modified in another page or from some other code.

    So i would recommend that you try to refactor your solution at some point to make it more robust to changes happening outside of your page. 

    Just thought that could be good information for others who read this thread later.

  • Morten Steengaard Profile Picture
    555 on at
    RE: Modify other line in form

    Hi all,

    Thank you very much for helping me!

    I have moved my code to "Sales Order Subform" OnModifyRecord trigger and have added CurrPage.Update(false); after creating/updating the other record. That solved the problem.

    Thanks,

    Morten

  • Suggested answer
    Nitin Verma Profile Picture
    21,571 Moderator on at
    RE: Modify other line in form

    Try to move your code from Sales line table to Sales Order Subform page (46), trigger OnModifyRecord(): Boolean trigger, and use currpage.update function after all done.

    I hope it will help you.

  • Verified answer
    YUN ZHU Profile Picture
    86,030 Super User 2025 Season 1 on at
    RE: Modify other line in form

    Hi, Very interesting attempt, Interesting to try, but I think there is some risk in adding it directly in the table's OnAfterModify() trigger, you can try adding it in the Sales Order page and then try the function below.

    Page.Update([Boolean]) Method

    https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/page/page-update-method

    Hope this helps.

    Thanks.

    ZHU

  • Suggested answer
    THE Italian Profile Picture
    on at
    RE: Modify other line in form

    Very hard to provide an answer to this. This depends on a wide variety of things.

    If this is SaaS then it is important to fully refresh the subform line.

    if you press F5 after you insert the line, is this working as expected? If yes, then this is the piece that you are missing.

    Otherwise, it might be something with re-reading the second line inserted (NST Caching).

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

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

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

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 2,655

#2
Mansi Soni Profile Picture

Mansi Soni 1,574

#3
YUN ZHU Profile Picture

YUN ZHU 1,453 Super User 2025 Season 1

Featured topics

Product updates

Dynamics 365 release plans