Wednesday, February 9, 2011

AX 2009 Batch Job Stuck In Executing

Having a batch job stuck in the Executing status in AX 2009 is a pretty common thing for me to get a call about when a customer is upgrading or doing an implementation.

One of the first things that I check is to make sure that the batch job that is stuck in executing has all tasks set to run on the server. You can check this out by going to Basic -> 'View Tasks' button -> 'Run location' field. If it is set to 'client', that is the issue. The next step is determining why this happened.

Check 1: Check the menu item (probably an Action or Output) and make sure the 'RunOn' property is set to 'Server'. If not, change it.

Check 2: Find the class where the 'runsImpersonated' override is. This value must be true. If it is false, change it.

Check 3: Look inside the code for anything that has a client call in it (hint: WinAPI calls a big culprit). If you find some, find an alternate way to do the task using server side calls instead of client(eg System.IO instead of WinAPI). If you're not sure if a method is running client or not, check the method declaration for the word client. If its there, its client. If nothing is there, use the call Global::isRunningOnServer() which will return a boolean of true if you are server side.

I'm sure you're asking yourself 'Why do I have to do this?!?! Couldn't Microsoft leave it like it was??'. There are a variety of reasons that this change was made and it's awesome. The biggest benefit is better performance because all of the processing is on the server so the client->server calls are eliminated. But maintenance and deployment is also a biggie.

The new AX 2009 batch engine does all of its processing on the server whereas the previous AX 4.0 batch engine ran the code client side. Because of this, batch jobs will get hung up if it makes a call that runs client side (aka WinAPI). AX 4.0 had to have services (at least that was our preferred method) that booted up the AX program and had a user run the program like a user and then kick off the process. Remember the little moving progress boxes? No more in the batch engine. Also NO MORE SERVICE MONITORING APPS RUNNING EXTERNAL TO AX! You can manage the batches from within AX now.

     warning('your browser is out of date...')


  1. Thanks for the info. One amendment:

    Basic -> 'View Tasks' button -> 'Run location' field.

    ... should read ...

    Basic -> Inquiries -> Batch job -> 'View Tasks' button -> 'Run location' field.

  2. Do you know how to remove a batch job that is set to run on the client and is stuck in executing status? Nothing seems to work.

    1. I've hit that scenario before and remember it being tricky. To solve the issue, my emails show I had the luxury of restarting that AOS it was running on so i could verify if it was still stuck in executing after. From there, I eliminated the non-executing shell record in the back end and the other recurring record picked up where the other left off. The job data should roll back from tts. Check that though. You dont need to restart AOS but it can be safer and cleaner that way.

      This of course wont help you if the issue is something other than the batch job running client. Make sure to check the methods are all running server too. sometimes ppl make calls to code that can only run on the client like WinAPI and that will cause issues even if the job says it is running server side.