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
- 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.
This is a topic close to my heart cheers. Thanks
The post has actually peaks my interest. I will bookmark your website and keep checking for new tips.
Great post. I’m confronting a couple of these difficulties.
Saved as a favorite, I really like your site!
I have a Vm deployment of Microsoft Dynamics 365. After developing a workflow for the Fixed Asset module, I realized the Microsoft Dynamics 365 for Operations: Batch Management Service, stopped and refused to run after trying multiple times.
Steps I’ve already taken:
— ran the command ‘iisreset’ in cmd
— viewed the Event log and saw: Batch thread threw a handled exception.
— and restarted my vm on several occasion.
Please, I need help with restarting the service and a possible reason why it happened.
I would check the batch job logs to see if one is erroring out, it appears that either the service or a batch job is hitting an exception that is caught/handled by the code but cannot continue.
Hi Alex,
short question to this topic, do you know a possibility to “start” a batch job from external via webservice?
Because we use for all other application an batch management framework and are interested if we can setup the “recurrence” externally and start the jobs in dynamics with a web service!?
Should be able to do set up a service operation endpoint that you can hit externally and then use the following X++ code to setup the batch job recurrence:
Setting up Batch jobs using X++ [Dynamics AX]
Create batch job through X++ code
Here it is how you can make your form batchable in Dynamics 365 for Finance and Operations:
https://ax.docentric.com/make-form-batchable-dynamics-365-finance-operations/
I have a problem with employee changing position takes almost an hour. Is there a way I can tell if there’s a batch job that processes the change of position?
Brian,
You would have to look at the code that executes when you perform the employee change to see the business logic.
HI Alex!
Question for you, is it possible to create a batch job that would import attachments to D365? If so, is it possible to attach them to certain records/types of transactions when imported? We have users that need to upload over a 1000+ attachments to D365 and clearly they are not thrilled to do it manually.
Would appreciate any advice. We are currently on .36 F&O and went we live with SCM the end of 2022.
Thank you!!
Bridget,
I think this would be possible but I haven’t tried doing this before, but here are some options I found:
You can upload a file from a local machine by following this example: https://dev.goshoom.net/2016/03/file-upload-and-download-in-ax-7/
Not sure where the files you want to upload are stored, but you can get a file from SharePoint by following this code: https://community.dynamics.com/forums/thread/details/?threadid=4b34ccdc-a39c-4035-ab0f-f256d30e2338
Another option for something like this would be to use Power Automate to help in the process: https://elearnd365.com/2021/06/04/using-power-apps-to-upload-document-attachments-in-fo/
Happy to discuss further!
The new version of D365 FinOps doesn’t have the place to link the batch group to a batch server and to make selected servers from remaining servers on the batch group.
Now I don’t know where and how to link the server to a group.
Here is a great overview of what happened to this configuration: https://blog.johanpersson.nu/2022/06/30/what-happened-to-batch-groups/
An excerpt from the blog post:
‘Starting with version 10.0.29 the default behavior is that all Batch Servers are assigned to all Batch Groups.’