Search code examples
axaptax++dynamics-ax-2009

is it necessary to revert something when using return inside a changeCompany


I have to add a control inside a changeCompany() in an existing class.

I suppose the code below is OK, but I have a doubt : Does the "return" order imply that a return to the original company is done ? Or is there to add a statement, unknown by me, something like revertToPreviousCompany()?

try
{
    changeCompany(companyId)
    {
        // the method will produce a message and return false if an error
        if (!this.doSomeChecks()) {               
           return;
        }          
        // much more code below 

Solution

  • Yes that is OK as in some situations you wouldn't even be able to revert it if not done by the runtime itself.
    Imagine a callstack in which you have try - catch around some code your are calling and you expect there may be thrown an error but if the code which calls your code already established a transaction your handler is not called and therefore you wouldn't have a chance to undo the changeCompany