In Dynamics 365 Finance and Operations (D365) batch jobs are used to automate different recurring processes throughout the system. Batch jobs can be scheduled to be run at different times and different recurrence schedules.
They can also be used to run a resource intensive or long running job on the server instead of running it interactively on the user’s browser which will lock up the UI during the processing period. Batch jobs are typically managed by a system administrator although I have seen certain power users from different departments take ownership over managing their respective batch jobs.
How To Put A Job In The Batch Queue
First, we will look at how to put a job in batch which just means that it will be in the batch queue and scheduled to run on the server automatically. In this example I will use the customer aging snapshot periodic job which is found in Credit and collections > Periodic tasks > Age customer balances. When this job runs it will update the aged balances of customers to reflect the current balances of the specified aging buckets (typically something like 30, 60, 90, 180, Days).
- To put a job into batch mode, click on the job and open the “Run in background” tab.
- Click the “Recurrence” button to set a recurrence. This recurrence form enables you to:
- Set the start date and time
- End the job after either a number of runs or after a certain date. If you want the job to run in perpetuity you can select the “No end date” option.
- In the “Recurrence pattern” section you can set how often the job should run. Depending on if you select Minutes, Hours, Days, Weeks, Months, or Years, you will get different parameter options on the right side of the form to help you get the recurrence you are looking for.
- Once you’ve got the recurrence set click “OK”.
Next click the “Alerts” button next to the recurrence button on the batch job form. You can set up alerts for different events related to the batch jobs by clicking the “Alerts” button. Select the events for which you would like to see an alert. You can have emails sent to you if you enable the email slider. To get the notification alert select the “Show pop-ups” option. This will display the alert in the notification center.
Next, to actually schedule the batch job you need to enable the “Batch job” flag. We need to also select a batch group.
A batch group is used to distribute the processing load of different jobs to different servers.
Once you have selected a batch group (typically there is a blank batch group set up that you can also select), click the “OK” button to put the job into batch. Then you will get a notification confirming that the job has been put in to the batch queue.
How To Pause And Resume A Batch Job
To see your batch job in the batch queue, navigate to System administration > Inquiries > Batch jobs.
This inquiry form shows all batch jobs are currently in the batch queue and the current status.
The statuses and definitions are listed below:
- Withhold – The batch job is withheld from the batch execution schedule.
- Waiting – The batch job is waiting to be executed at the scheduled time.
- Error – The batch job failed due to an error.
- Ended – The batch job has completed. Note: This does not mean the job ended without warnings or embedded errors. In some cases, there could be warnings messages that were thrown during execution that can be viewed in the individual batch history record shown in the section below. These are tougher to find because the majority of records might have been processed successfully but others were not. Since there were some that were successfully processed the system does not mark the entire batch job as having an “Error”. For this reason it is always good to have reports in place to monitor the completion of critical batch jobs that have a high risk of failure.
- Canceling – In some cases you may need to cancel a long running job in the middle of execution. This status indicates that the job is currently being canceled but has not yet ended. Depending on the job there may be a rollback procedure that executes as soon as the job enters “Canceling” status.
When you submit a job to the batch queue the status will start with “Waiting” until the scheduled run time. If you want to pause the batch job and prevent it from running, you can click the “Change status” button. Then you can click the “Withhold” status. The batch job status will be changed to “Withhold” and the job will be prevented from running.
When you are ready to resume the job you can change the status back to “Waiting” and this will resume the batch schedule. Note: If you change the status back to “Waiting” and the “Next scheduled start date/time” is in the past, the batch job will run immediately. I have run into this a couple of times where I wanted to resume the job at the “normal” time but the next scheduled time was in the past and the job ran as soon as I put it back in “Waiting” status so make sure you check the “Next scheduled start date/time” before you resume the job.
There are cases where batch jobs need to be scheduled in a certain sequence for various reasons. This can be done by creating a new batch job from the batch job list queue and manually adding the jobs as batch tasks.
- Navigate to System administration > Inquiries > Batch jobs.
- Click the “New” button.
- Enter a description of the Batch Job.
- In the “Batch tasks” section is where you can add all the jobs that need to be run. You can click “New” to add the jobs.
Unfortunately, you will need to know the AOT class name of the job. So if you don’t know it you can put the job in batch and set it to “Withhold” so it doesn’t run, click on the batch job ID to drill into the job, and in the “Batch tasks” pane you will see the class name.
Once you have added all your tasks to the batch job, in the lower pane you can set constraints for the selected job to run. You can select predecessor jobs and use the “Any” or “All” condition to determine if the job needs to wait for all tasks to reach the selected state or any of the jobs before the selected job can run.
How To View Batch Job History
Each time a batch job runs a record is created in the batch job history table. This batch job history record contains details about when the job ran, the result of the job, and any error, warning, or info logs the system might have thrown.
Batch Job History Cleanup
Over time the batch job history records can start to pile up. Depending on how many jobs you have running and the frequency they run, you might start to have performance impacts if you don’t clean them up (by clean up I mean delete them). Fortunately, there is a batch job history job in System administration > Periodic tasks > Batch job history cleanup (custom) that does just that.
- In the “History limit (days)” field you can specify that you want to delete batch job history records older than a certain number of days old.
- In the “Records to include” section you can click on the “Filter” button and filter to delete the batch history records of only specific batch jobs. So, if you wanted to delete the history of some jobs that are accumulating lots of records but keep the history of other batch jobs this filter mechanism would allow you to do that.
- Then to have this batch job run in batch click the “Batch processing” slider, select a “Batch group” and click the “OK” button. This will add the job to the batch job queue. Each time the job runs it will use the parameters you have given it to delete the batch job history records and help to keep database growth under control.
Batch jobs offer excellent control and monitoring power to automated process throughout the system. The more and more your ERP system becomes automated the more important it becomes to understand the capabilities and functionality of batch job management.