How to do it...

  1. Open the alExtensibleAppProject folder in Visual Studio Code.
  2. In Explorer, select Transaction Entry.al. In the Editor, add a new event publisher to the table:
[IntegrationEvent(false, false)]
local procedure OnBeforeGetLastDirectUnitCost(var TransactionEntry: Record "Transaction Entry"; var IsHandled: Boolean)
begin
end;
  1. In the GetLastDirectUnitCost() function, create a new local variable:
IsHandled: Boolean;
  1. Now, raise the event at the start of the GetLastDirectUnitCost() function:
OnBeforeGetLastDirectUnitCost(Rec, IsHandled);
  1. After the call to the event, add logic to exit the function if the subscriber has set IsHandled to true:
if IsHandled then
exit;

Your function should now look like this, with the new code highlighted as follows:

procedure GetLastDirectUnitCost()
var
PurchaseInvLine: Record "Purch. Inv. Line";
IsHandled: Boolean;
begin
OnBeforeGetLastDirectUnitCost(Rec, IsHandled);
if IsHandled then
exit;
clear("Unit Cost");

if "Item No." = '' then
exit;

PurchaseInvLine.SetRange(Type, PurchaseInvLine.Type::Item);
PurchaseInvLine.SetRange("No.", "Item No.");
if PurchaseInvLine.FindLast() then
validate("Unit Cost", PurchaseInvLine."Direct Unit Cost");
end;

It's that easy!

Now, a subscriber can take over the function, as well as perform its own calculation and bypass the rest of the logic within the function.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.64.172