Insufficient Memory when using events

The following code crashes the client:

[Code]
Object.SETRANGE(Type, Object.Type::Table);
Object.FINDSET;
REPEAT
  RecRef.OPEN(Object.ID);
  OnBeforeDataItem(RecRef, Allowed); // This is an integration event
  ExportRecord(RecRef);
  OnAfterDataItem(RecRef); // This is another integration event
  RecRef.CLOSE();
UNTIL Object.NEXT = 0;
[/Code]

These events have no subscribers

Thank you Microsoft !!!!

Parents
  • OK, Update:

    It is not possible to call more than 998 Events in a row - even though there is no subscriber.

    This also means that it might not be possible to post a journal with more than 998 lines in it.

    The following code also fails:

    FOR I := 1 TO 1000 DO
        OnAfterExportRecord(RecRef);

     

    Anyway - it seems that I found a workaround.

    Instead of creating the events as local functions in the CU where it should be (like posting CU), we create them in a seperate codeunit as local events, then we create a function in that CU which calls the Event:

    LOCAL [IntegrationEvent] OnBeforeSomething(VAR RecRef : RecordRef;VAR Allowed : Boolean)

    RaiseOnBeforeSomething(VAR RecRef : RecordRef;VAR Allowed : Boolean)
    OnBeforeSomething(RecRef,Allowed);

    Then call the RaiseFunction in the EventRaiser CU and it works for a million records (as far as I have seen),

    Even though this is a valid workaround, it is a nightmare and a pain to have to consume another object just becase of raising events.

     

    Conclusion: Never raise an event in the same object where you declare it !!!

Reply Children
No Data
Related
Recommended