Tuesday, February 26, 2019

NAV BC - Extension example - Subscribe to Publisher and execute custom codeunit


  • When the customer is changed, the built-in publisher publishes the event and the Rec and xRec variables
  • The subscriber is triggered by the publish, picks up the Rec and xRec variables as parameters and executes the current AL function to display only the address before (xRec) and after (Rec) change fields
  • Procedure also executes a custom CAL function 50002

codeunit 50100 ExtToolbox
{

trigger OnRun()
begin

end;

var
myInt: Integer;

[EventSubscriber(ObjectType::Page, Page::"Customer Card", 'OnAfterValidateEvent', 'Address', true, true)]
procedure ChangeMessage(var Rec: Record Customer; var xRec: Record Customer)

var
msg: Text[30];
msg2: Text[30];
MyObject: Codeunit 50002;
begin
msg := xRec.Address;
msg2 := Rec.Address;
Message('Old Value:' + msg + ' | New Value: ' + msg2);
MyObject.Run;
end;
}

No comments:

Post a Comment