In Microsoft Dynamics 365 Finance and Operations, we can perform reoccurrence tasks using batch jobs functionality. With this batch job functionality we can make any task that is recurring automatic in the backend without any human intervention.
Microsoft Dynamics 365 Finance and Operations batch job has 2 framework:
1. Run base framework: This is the legacy framework for D365 batch job, which Microsoft is not supporting any more and is recommending all users to switch to SysOperation for all new processes.
2. SysOperation framework: This is the latest framework for D365 batch job, which Microsoft prefers for new updates and fucntionalities.
In this blog on D365 batch job, we will be talking about SysOperation framework, This framework has majorly 3 classes as below
1. Service class: Service class extends SysOperationServiceBase class and contains the logic for the batch operation.
2. Data Contract class: Data contract class implements SysOperationValidatable. Data contract class is class that defines parameters needed for batch operations which are provided by users.
3. Controller class: Controller class extends SysOperationServiceController class and It holds information about the batch operation like execution mode, show dialog or progress bar etc. and directs the batch operation.
In the below example I will show a batch job in which user will enter From Date and To Date, and pass same to main process method, where you can write code/logic accordingly.
Service class for D365 batch job:
class DCCancelSalesOrderService extends SysOperationServiceBase
{
TransDate StartShipDate, CancelShipDate;
/// <summary>
/// ProcessOperation method for logic
/// </summary>
/// <param name = "_contract">Contract</param>
public void processOperation(DCCancelSalesOrderContract _contract)
{
StartShipDate = _contract.parmstartshipdate();
CancelShipDate = _contract.parmcancelshipdate();
if(StartShipDate && CancelShipDate)
{
Info("Both dates entered.");
}
}
}
Contract class for D365 batch job:
[
DataContractAttribute
]
public class DCCancelSalesOrderContract implements SysOperationValidatable
{
TransDate startShipDate, cancelShipDate;
/// <summary>
/// parmstartshipdate date parameter
/// </summary>
/// <param name = "_startShipDate">_startShipDate</param>
/// <returns>startShipDate</returns>
[
DataMemberAttribute(identifierStr(StatrShipDate)),
AifCollectionTypeAttribute('startShipDate', Types::Date),
SysOperationLabelAttribute(literalStr("@DC:DCStartshipdate")),
SysOperationDisplayOrderAttribute('1')
]
public transdate parmstartshipdate(TransDate _startShipDate = startShipDate)
{
startShipDate = _startShipDate;
return startShipDate;
}
/// <summary>
/// parmcancelshipdate
/// </summary>
/// <param name = "_cancelShipDate">_cancelShipDate</param>
/// <returns>cancelShipDate</returns>
[
DataMemberAttribute(identifierStr(CancelShipDate)),
AifCollectionTypeAttribute('cancelShipDate', Types::Date),
SysOperationLabelAttribute(literalStr("@DC:DCCancelshipdate")),
SysOperationDisplayOrderAttribute('2')
]
public transdate parmcancelshipdate(TransDate _cancelShipDate = cancelShipDate)
{
cancelShipDate = _cancelShipDate;
return cancelShipDate;
}
/// <summary>
/// Validate method
/// </summary>
/// <returns>boolean for isValid</returns>
public boolean validate()
{
boolean isValid = true;
if (!startShipDate)
{
isValid = checkFailed(strFmt("@SYS84753", "@DC:DCStartshipdate"));
}
if (!cancelShipDate)
{
isValid = checkFailed(strFmt("@SYS84753", "@DC:DCCancelshipdate"));
}
return isValid;
}
}
Controller class for D365 batch job:
class DCCancelSalesOrderController extends SysOperationServiceController
{
/// <summary>
/// New
/// </summary>
protected void new()
{
super();
this.parmClassName(classStr(DCCancelSalesOrderService));
this.parmMethodName(methodStr(DCCancelSalesOrderService, processOperation));
this.parmDialogCaption("Batch operation dialog title");
}
/// <summary>
/// Caption
/// </summary>
/// <returns>Caption</returns>
public ClassDescription caption()
{
return "Batch operation task description";
}
/// <summary>
/// Main method for controller class
/// </summary>
/// <param name = "args">args</param>
public static void main(Args args)
{
DCCancelSalesOrderController controller;
controller = new DCCancelSalesOrderController();
controller.startOperation();
}
}
Now just create an action menu item and put the object type property of menu item as class and In the object property put the Controller class.
This was all about single threaded D365 batch job.
You can also check out my blog on Multithreading D365 batch job: Multithreading D365 Batch Job
Need help? Connect Atul
- D365 Data entitiy Insert method COC - October 30, 2024
- D365 Joins - October 16, 2024
- D365 Find method and Exist method - October 9, 2024