Hi experts,
I use a Business Central wave 2 - fall 2020 on-premise.
I have made a table extension for "Purchase Line" and a page extension for "Purchase Order Subform". I have added a few new fields in those two.
I need to add some validation that depend on what item the user enter into the "No." field. So if the user enters "Item A", my validation demands that my new fields must be entered also. But if the user enters "Item B", my validation should not give an error message.
I have made my validation on the trigger "OnBeforeInsert" in the table extension. It works fine.
The problem is that if I call my validation in the trigger "OnBeforeModify", then I get the error message when the user changes "No." from "Item B" to "Item A". It says that the user has to enter values in the other fields, but the user has not moved to those fields yet. The problem must be that "OnBeforeModify" is called while the user is standing on the same record in the list page.
It is important that the user does not leave the line with bad data.
Is there another trigger/event, that I should use? (In AX there is a method that is called when a user tries to leave a record.)
Or can I see somehow what the user is doing, so that my validation is called sometimes when the "OnBeforeModify" trigger is activated, and sometimes my validation is not called?
Table extension and page extension:
tableextension 50103 PurchaseLine extends "Purchase Line"
{
fields
{
field(50000;"My Field";Integer)
{
DataClassification = ToBeClassified;
Caption = 'The field';
}
}
trigger OnBeforeInsert()
begin
//ValidateMyField();
Message('OnBeforeInsert table');
end;
trigger OnAfterInsert()
begin
Message('OnAfterInsert table');
end;
trigger OnBeforeModify()
begin
Message('OnBeforeModify table');
//ValidateMyField();
end;
trigger OnAfterModify()
begin
Message('OnAfterModify table');
end;
}
pageextension 50103 PurchaseOrderSubform extends "Purchase Order Subform"
{
layout
{
addbefore("Quantity")
{
field("My Field"; Rec."My Field")
{
ApplicationArea = All;
ToolTip = 'Something';
}
}
}
}