New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[question/issue] Rec.CHANGECOMPANY with event subscribers #3823
Comments
Since triggers not on the record are not run in the changed company, then the recommended pattern is to avoid writing to a different company. This can be obtained by creating a new background session in the 'destination company' which does the writing and then it only reads from the original company. However, be aware that the two sessions do not run in the same transaction, and hence transaction integrity cannot be assured across the two sessions. |
That these triggers are not run in the different company may not be an good idea. I would recomend to fire the triggers in the destination record's company by default (i personaly do not know a case where it should be different, but may be). |
This is how Business Central (NAV) worked since the beginning, and it's documented here:
This is why we recommend to create a new background session in the destination company, that will triggers all the proper "events/triggers" in the right company, and not the current one. |
May that this is documented. but i know no subscriber which checks this. And once again: A performant System is eventdriven. Sessions that eventualy run in background are nothing you should rely on, because it's out of sync, and if there is an error, the data may be compromised. |
Thanks for the input, but changing now the behavior of CHANGECOMPANY would be breaking. If we decide to change the way events and/or CHANGECOMPANY works this will be definitively considered. About the background session and error handling/data compromised, you can consider relying instead on the task scheduler (https://docs.microsoft.com/en-us/dynamics-nav/task-scheduler) |
Sorry i know how bad the job queue in NAV works, i think there is no realy difference in BC or NAV2018. |
Have a look on the CHANGECOMPANY- calls in the standard- code, and understand what may happen, if an potential eventsubscriber is called in the wrong company. |
The owning team has been made aware of the problem but there are currently no plans to address it. I will close the issue here since it's not directly related to developer tools and AL language. |
Scenario:
A given record with event- subscriber is inserted/modified/deleted with a CHANGECOMPANY before.
How can we preserve an (unknown) event- subscriber to be fired that it modifies data in the current company where the record- data probably does not exist?
Currently in C/AL we call INSERT/MODIFY/DELETE with FALSE, and the associated trigger is not fired.
The text was updated successfully, but these errors were encountered: