78

Enabling the new property (TransactionInstance: Boolean) would mean that the codeunit works like a Single Instance codeunit for the duration of the current transaction. Once the transaction has committed or rolled back then the codeunit is cleared.


The reason for this is that we need to use single instance codeunits a lot more in AL than we did in NAV, because of the way we now need to use events to change functionality in BC. For example we may subscribe to events ABC and XYZ and we need to save a variable from ABC and use in XYZ.


This can be achieved using Single Instance codeunits, but there is a risk that "dirty data" is left behind if ABC is called and then an error occurs. We have to be careful about trying to detect and avoid this scenario (not always possible) and if we don't we can end up with undesirable results.


I know we can use manually bound event subscribers to achieve something similar but this is not always possible and having a "Transaction Instance" codeunit would work perfectly, be extremely simple to use and make our lives a lot easier.

Category: Development
STATUS DETAILS
Needs Votes
Ideas Administrator

Thank you for this suggestion! Currently this is not on our roadmap. We are tracking this idea and if it gathers more votes and comments we will consider it in the future. Best regards, Business Central Team

Comments

K

Very clever idea. Would be much appreciated

Category: Development

K

That's a really good idea.This should be taken even further and record variables should also be enhanced with this flag. For larger amounts of data that are only valid within the session and are then automatically removed.MySessionData : Record "Session Data" sessionOnly;

Category: Development

K

Good one, and we'll needed

Category: Development