AL icon indicating copy to clipboard operation
AL copied to clipboard

Sugesstion: Improvement of Event Filtering

Open megel opened this issue 7 years ago • 1 comments

The Filtering of EventSubscription could be used to improve

  1. performance
  2. reduce the code

This Code in the Codeunit is called also on Rec.DELETEALL(FALSE);

[EventSubscriber(ObjectType::Table,18,'OnAfterDeleteEvent')]
local procedure MyEventName(var Rec, bool RunTrigger);
begin
  IF RunTrigger THEN BEGIN
     // ...
  END;
end;

The Codeunit with this subscriber will only be instantiated and called, when the Filter of the subscription is passed. I have used an EventAggregator with Subscription Filtering (https://msdn.microsoft.com/en-us/library/ff921122.aspx) in other projects.

A syntax could be:

[EventSubscriber(ObjectType::Table,18,'OnAfterDeleteEvent', RunTrigger = TRUE)]
local procedure MyEventName(var Rec, bool RunTrigger);
begin
  // Subscriber is only active (called) on RunTrigger = TRUE
end;

megel avatar Jun 28 '17 09:06 megel

That's all well and good if Navision were able to run lots of code in a constructor, but Navision doesn't have constructors so there's no complexity here. It should be quite reasonable for the compiler to automatically include this as well defined optimisation without having to complicate or change the syntax.

If constructors are added then a precondition lambda expression would be very nice.

rdebath avatar Jul 06 '17 14:07 rdebath