Cancellation Batch job in AX2012

Hi, I would like to understand what exactly happens when you cancel a batch Job?

For example, if I have scheduled a batch job of “Crediting invoices” for a set of invoices, and at certain stage while the job is still executing, If I cancel the job what exactly happens?

I understand, that the moment when user changes the status of the batch to cancelling, the job will be in “cancelling” status for a while, and it will role back all open transactions.

what we observed is there are invoices credited even after the moment the job status is changed to cancelling, this should not be the case right?

Can any one have more insights on how cancellation of batches work? or any explanation of the above situation?

Any pointer are much appreciated!!

Can anyone please help me with more info on this?

I think it terminates running worker threads (in addition to changing status of batch tasks); progress done by completed tasks isn’t rolled back.
But I don’t know it in detail - I suggest you debug the code if you want to see what exactly happens at runtime.

Yes, I’m sure that the completed tasks wont be rolled back, transactions which are open/and the tasks which are executing will start rolling back the moment when change the status of the batch to cancelling, what I would like to know if would there be any chance that the tasks which are completed are still executing even after the batch is moved to cancelling status? is that possible… what all possible situations are possible after cancellation of batch?

I’m looking for any documentation which can explain about the processes when the batch status is changed.

Can anyone help with it?

No, it’s not possible that a task would be executing and completed at the same time. If it’s executing, it’s not completed yet; if its execution is completed, it’s clearly not executing anymore.

That is my understanding as well, How is it possible in some situation that, while the batch status is in cancelling status and there are still some tasks which were in executing status are committed instead of rolling back the moment the batch status is moved to cancellation?

Any documentation from MS explaining what exactly happens during the status change of a Batch Job?

Maybe they committed changes before completing. Maybe they were not completed when the cancellation request was issued, but they completed before they could be shoot down. Maybe they were already completed but you weren’t looking at up-to-date data about status.

Yeah, I know we have to Relay on “MAY BE” in such situations :slight_smile:

I have to ask this again and again because it is so weird happening.

There was a batch in Executing status (for example - posting invoices)
For testing purpose, I had cancelled the batch
The batch will take some time to Move its status from “Cancelling” to “Cancelled”, since it has to rollback open/executing tasks which are not completed (Obviously).

However how is it possible that there are invoices posting even after couple of hours the bath is moved to “Cancelling” status?
The batch kept on posting the invoices till the last moment that the batch is moved to cancelled status.

If you want to understand what exactly happens in your specific scenario, debug it. Use my previous reply as a checklist of things that you should verify, because of one of them is likely the answer.