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...
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;
I have the same question (0)
  • Suggested answer
    THE Italian Profile Picture
    on at

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

  • Verified answer
    YUN ZHU Profile Picture
    95,729 Super User 2025 Season 2 on at

    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
    Nitin Verma Profile Picture
    21,708 Moderator on at

    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.

  • Morten Steengaard Profile Picture
    555 on at

    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
    Inge M. Bruvik Profile Picture
    1,111 Moderator on at

    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

    Hi Inge,

    You are absolutely correct.

    Best regards,

    Morten

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,362

#2
YUN ZHU Profile Picture

YUN ZHU 867 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 607

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans