A batch job in D365FO is a collection of tasks that are processed automatically by the AOS. Tasks in a batch job can be run sequentially or simultaneously. You can also create dependencies and decision trees between tasks based on whether previous tasks succeed or fail.

The first step of creating the batch job is to create the X++ batch class with the code you would like to execute, a simplistic version of the required setup of this class is below.

Code Side Setup

public class YourBatchJob extends RunBaseBatch
{
 public void run()
 {
 //Code to execute
 }

//Needs to be set to true so class can be ran in a batch
 boolean canGoBatch()
 {
 return true;
 }

//Stores parameters of the batch
 public container pack()
 {
 return conNull();
 }

//Returns the stored object for the batch to use
 public boolean unpack(container packedClass)
 {
 return true;
 }

//Determines whether to run on server or client
//True - Server; False - Client
 public boolean runsImpersonated()
 {
 return true;
 }
}

Setup within Dynamics 365 for Finance and Operations

  1. The first step in setting up a batch job is creating a batch group, a batch group allows you create a collection of batch jobs to execute
  • To set up a batch group go to System Administration -> Batch Groups
  • From here you can create new batch groups as well as determine which batch servers you want to process a certain batch group

2. Next, you can actually create a batch

  • To do this go to System Administration -> Batch Jobs
  • When you create a new batch job you will be able to give the batch a description
  • Batches within D365FO can have a number of Statuses the most important ones are below:
    • Withhold – batch will not be picked up for execution, batches need to be in this status to edit
    • Waiting – batch will be picked up for execution at next recurrence schedule
    • Executing – batch is currently being executed
    • Ended – batch processes successfully

3. Once you create the batch job, selecting the batch job row in the grid and then clicking Batch Job menu bar will give you options on what you can do next

  • View Tasks – shows the individual tasks of the batch
  • Batch Job History – shows status of previous executions of the batch
  • Recurrence – set up the schedule to execute the batch
  • Alerts – set up alerts for different events of the batch
  • Change Status – changes the status of the batch

4. If you navigate to View Tasks you can set up the tasks the batch will execute, if you add a task you will need to set:

  • Task description – allows you to provide a description of the task
  • Company Accounts – displays which legal entity the batch runs against
  • Class Name – the X++ class name that you want to execute
  • Run Location – will either be client (if no impersonation) or server (if using impersonation)
  • Batch Group – can be set to the batch group that you want the batch to execute with

5. The next step is to set the recurrence of the batch job, this will determine on what schedule the batch job is executed

6. The final step is to change the status of the batch from ‘Withhold’ to ‘Waiting’, once this is done the next time the batch is set to execute the batch process will pick it up and process it

 

Final Note: It appears in DEMO/DEV instances of Dynamics 365 that the Batch Management Service is not set to start by default with the machine, this service needs to be on for batches to be processed.