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 !!!!
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 !!!
Sounds like a bug to me. I think the event should be in the same object, and hidden from the editor.
I would consider this being a bug as well,
Based on the tests I ran, the events went never out of scope after raising them, I had a lot of them in the call stack in certain combinations.(I plqayed around to see if to raise the events from main code or from other local procedures, splitting up my code.