Modify other line in form

MortenSteengaard
Member Posts: 144
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;
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;
0
Best 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,
Morten0
Answers
-
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)0 -
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,
Morten0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions