Modify other line in form

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;

Best Answer

  • MortenSteengaardMortenSteengaard Member Posts: 130
    Answer ✓
    Hi Resolus,

    Thank you for your reply.

    I am sure, that your suggesting would solve the problem. However, I have got another solution on the Microsoft Forum:

    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 once again,

    Morten

Answers

  • ResolusResolus Member Posts: 40
    I can see that work for creating the new line, but not for updating.
    You only have an insert here?

    I'd split the code into 2 parts.

    A trigger, OnAfterInsert or OnAfterModify, for inserting the second line.
    And for updating you should create a procedure that updates the quantity of the second line.
    Call that from the OnValidate event of the Quantity field on the page, and after the procedure call you could try CurrPage.Update(true);
    That saves the change you just did and refresh the page. (reload the data)
  • MortenSteengaardMortenSteengaard Member Posts: 130
    Answer ✓
    Hi Resolus,

    Thank you for your reply.

    I am sure, that your suggesting would solve the problem. However, I have got another solution on the Microsoft Forum:

    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 once again,

    Morten
Sign In or Register to comment.