Hi Experts,
I was using AL for creating new table/page by extension.
I came across a requirement where I want to add an additional validation code in OnValidate trigger of a field in Item table by extension.
Can you please suggest as I kind of got stuck.
Regards
0
Answers
Really? I have not done anything with AL, but since events OnBeforeValidateEvent and OnAfterValidateEvent are there to be used from within C/AL, I suppose they must be there from AL also. In C/AL you get an additional property to choose the field, once you have chosen one of the two events mentioned before.
HTH
Ex. Customer table
tableextension 70050090 CustomerExtension extends Customer
{
fields
{
modify(Name) // Modify the existing name field.
{
// Customizable properties can be changed here.
CaptionML = ENU = 'My Changed Caption';
trigger OnBeforeValidate();
begin
// Before validating customer name
end;
trigger OnAfterValidate();
begin
// After validation customer name
end;
}
}
}
OnBefore or After usually is enough for most validation tasks. Like add extra validation.
And a function with something like this:
codeunit 50000 MyEventsubscribers
{
[EventSubscriber(ObjectType::Table, Database::Item, 'OnAfterValidateEvent', 'Description 2', false, false)]
local procedure OnAfterValidateEvent(VAR Rec: Record Item; VAR xRec: Record Item)
var
begin
end;
}
I will try to execute your advice and revert
All your answers, helped me a lot. I kind of understood after trying out few scenarios that you can do most of the stuff by extending a page or its base table, just need think a bit on the logic. For others we need to go with an work around.