Wednesday 11 September 2013

Dependable batch jobs in AX with reference to external databases


There are tasks in AX which you want to run in a sequential order. For instance, you'd want the posting of the packing slips to be done before the invoice run and you want Forecast scheduling to be run prior to Master scheduling. 


When running these tasks in batch, you can can calculate some expected time frames and start task A at 4.00 AM and task B at 6.00 AM. However, when task A doesn't finish in time, it could have effect on task B. 

To prevent this from happening, you can build in some dependencies in AX. 

First create a new batch job with a recognisable description and click [View Tasks].


Here you create a new line manually, select the company account and select the classes you need:




"In order to appear in the list of selectable classes, the class needs the method canGoBatchJournal with the return value = true."
After adding a second (or third or fourth) job, you can add a dependency. In the 'Has conditions" grid you can add the condition that the Forecast needs to be 'Ended' before MRP can start. If for some reason, Forecast runs into an error, MRP will not start. 



So this principe is great, but what's even greater if we can start a batchjob which depends on data in an external database. So I created a simple class which checks an external database and copies some info to AX (how to can be found here: http://msdn.microsoft.com/en-us/library/ee677510.aspx). How cool is that :), the options are numerous, check if data is copied, check if data is present on another place, check if updates have been completed succesfully prior to the next jobs you want to run in AX.

Again setup up dependencies let forecast start when the call to the external databases has ended and let MRP start when Forecast has ended:



This way, all tasks are executed sequentially and will only start when a previous step has ended.