OnAfterValidateEvent of Table Field in Business Central:
What is an Event?
To handle events, you design event subscribers. Event subscribers determine what actions to take in response to an event that has been raised. An event subscriber is a method that listens for a specific event that is raised by an event publisher.
There can be multiple subscribers to the same event from various locations in the application code. When an event is raised, the subscriber methods are run one at a time in no particular order. You can’t specify the order in which the subscriber methods are called.
OnAfterValidateEvent of Field:
It’s executed after a field is validated when its value has been changed.
|[EventSubscriber(ObjectType::Table, Database::<Table Name>, ‘OnAfterValidateEvent’,|
‘<Field Name>’, <SkipOnMissingLicense>, <SkipOnMissingPermission>)]
local procedure MyProcedure(Rec: Record, xRec: ,CurrFieldno: Integer)
Update “GSTGroupCodeForSale” & “HSNSACCodeForSale” at the time of entering Item No. in the Sales Order. As
shown in the figure.
|codeunit 50001 “Custom Functions-01”|
[EventSubscriber(ObjectType::Table, Database::”Sales Line”, ‘OnAfterValidateE
vent’, ‘No.’, False, False)]
procedure OnAfterValidateSOLine(Rec: Record “Sales Line”; xRec: Record “Sales
Line”; CurrFieldNo: Integer)
GetItem: Record Item;
if Rec.Type = Rec.Type::Item then begin
if (GetItem.HSNSACCodeForSales <> ”) and (GetItem.GSTGroupCodeForSal
e <> ”) then begin
rec.Validate(“GST Group Code”, GetItem.GSTGroupCodeForSale);
rec.Validate(“HSN/SAC Code”, GetItem.HSNSACCodeForSales);