0% found this document useful (0 votes)
142 views13 pages

Batch Jobs in D365FO

Batch jobs in Dynamics 365 Finance and Operations (D365FO) automate tasks like report printing and invoice processing, allowing for scheduled execution. The document outlines two frameworks for creating batch jobs: the Run Base Batch Job Framework and the enhanced Sys Operation Framework, detailing their functionalities and benefits. It also provides a step-by-step guide for creating a batch job to automate Purchase Orders from approved Purchase Requisitions, including the necessary controller, service, and contract classes.

Uploaded by

csediveyanand
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
142 views13 pages

Batch Jobs in D365FO

Batch jobs in Dynamics 365 Finance and Operations (D365FO) automate tasks like report printing and invoice processing, allowing for scheduled execution. The document outlines two frameworks for creating batch jobs: the Run Base Batch Job Framework and the enhanced Sys Operation Framework, detailing their functionalities and benefits. It also provides a step-by-step guide for creating a batch job to automate Purchase Orders from approved Purchase Requisitions, including the necessary controller, service, and contract classes.

Uploaded by

csediveyanand
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Batch Jobs

MS D365 FO
What is Batch Job?

 Batch jobs in Dynamics 365 Finance and Operations (D365FO) are a


collection of tasks that are processed automatically by the Application
Object Server (AOS). These tasks can be run sequentially or
simultaneously. Batch jobs can include tasks for printing reports,
performing maintenance, or sending electronic documents. You can
set up recurrence patterns for batch jobs, for example, you can set up
a job to process invoices automatically at the end of every month.
Batch groups are used to categorize batch tasks and run them on
specific servers.
2 Types of Framework

 Run Base Batch Job Framework


The Run Base Batch Job Framework is a development framework in
D365FO that provides a standardized way to create and execute long-
running operations, such as batch jobs and reports. It allows
developers to define the input parameters for an operation, validate
them, and present a user interface to the end-user for input.
2 Types of Framework

 Sys Operation Framework


The Sys Operation Framework is an enhancement of the Run Base
framework and provides additional features and benefits. It provides
a standardized way to create and execute long-running operations,
with better separation of concerns between the client and server,
improved scalability and performance, and better error handling and
logging. Developers can use the SysOperation framework to create
custom batch jobs and reports, as well as other long-running
operations. The framework provides a flexible and extensible
architecture that allows developers to customize and extend it to
meet their specific needs.
How to create Batch Jobs in D365FO

 Lets create a Batch Job that automates the creation of Purchase


Orders (POs) from approved Purchase Requisitions (PRs). This
streamlines the procurement process, ensuring efficiency and
accuracy.
Controller Class: This class controls the
execution of the batch job.
 class SysOperationBatchController extends SysOperationServiceController
{
protected void new()
{
super(classStr(SysOperationBatchService),
methodStr(SysOperationBatchService, Process),
SysOperationExecutionMode::Synchronous);
}

public ClassDescription defaultCaption()


{
return "Process Job";
}

public static SysOperationBatchController construct(SysOperationExecutionMode _executionMode = SysOperationExecutionMode::Synchronous)


{
SysOperationBatchController controller;
controller = new SysOperationBatchController();
controller.parmExecutionMode(_executionMode);
return controller;
}

public static void main(Args _args)


{
SysOperationBatchController controller;
controller = SysOperationBatchController::construct();
controller.parmArgs(_args);
controller.startOperation();
}
}
Controller Class: This class controls the
execution of the batch job.

 The SysOperationBatchController class extends


SysOperationServiceController for batch processing. It overrides the
new method to set up the controller, provides a default caption, and
includes a construct method to create instances. The main method is
the entry point, setting up and starting the operation with given
arguments.
Service Class

 Service Class: The class SysOperationBatchService extends the


SysOperationServiceBaseThis class contains the business logic for the
batch job. It is where the actual processing of the batch job occurs. In
this case, the Service class contains the logic to automate the
creation of Purchase Orders (POs) from approved Purchase
Requisitions (PRs). This class is invoked by the Controller class to
execute the operation.
Service Class
 public class SysOperationBatchService extends //Insert Value In Purchase Line
SysOperationServiceBase
{ purchLine.initValue();
/// <summary>
/// while select * from PurchReqLine
/// </summary>
/// <param name = "_contract"></param> where PurchReqLine.PurchReqTable == _recID
public void Process(SysBatchContract _contract) {
{ ttsbegin;
PurchTable purchTable; purchLine.clear();
PurchLine purchLine; purchLine.PurchId = purchTable.PurchId;
PurchReqTable purchReqTable; purchLine.PurchPrice = PurchReqLine.PurchPrice;
PurchReqLine PurchReqLine;
NumberSeq numberSeq; purchLine.ItemId = PurchReqLine.ItemId;
VendTable VendTable; purchLine.Name = PurchReqLine.Name;
AccountNum _AccountNum; PurchLine.PurchQty = PurchReqLine.PurchQty;
PurchReqId _purchReqId;
RecId _recID; purchLine.LineAmount = PurchReqLine.LineAmount;
purchLine.VendAccount = _AccountNum;
_AccountNum = _contract.parmAccountNum();

while select forupdate * from purchReqTable purchLine.createLine(false, true, true, true, true, true);
where purchReqTable.RequisitionStatus ==
PurchReqRequisitionStatus::Approved ttsCommit;
{
}
_recID = purchReqTable.RecId;
ttsbegin;
ttsbegin;
numberSeq = purchReqTable.RequisitionStatus =
NumberSeq::newGetNum(PurchParameters::numRefPurchId( PurchReqRequisitionStatus::Closed;
)); purchReqTable.update();
numberSeq.used();
purchTable.PurchId = numberSeq.num(); ttscommit;
}
purchTable.initValue(); }
purchTable.initFromVendTable(VendTable::find(_AccountNum)
); }
Service Class

 With the addition of the Service class, the batch job becomes more
modular and maintainable.
 Since PO created against some vendor Account so we need to create
contract class to pass the parameters
Contract Class

 This class defines the data contract for the batch job. It contains methods to get and
set the values of the parameters that are entered in the dialog box.

[DataContractAttribute] public ACCOUNTNUM parmAccountNum(ACCOUNTNUM


_AccountNum = AccountNum)
class SysBatchContract implements {
SysOperationValidatable AccountNum =_AccountNum;
{ return AccountNum;
}

ACCOUNTNUM ACCOUNTNUM; public boolean validate()


{
[DataMemberAttribute('Vendor Account'), boolean isValid = true;
if (!ACCOUNTNUM)
AifCollectionTypeAttribute('Vendor Account', {
Types::String), isValid = checkFailed("Account Number is required.");
SysOperationLabelAttribute(literalStr("Vendor }
Account")), return isValid;
}
SysOperationHelpText(literalStr("Reterive Vendor }
AccountNum From Vendor Table"))]
Contract Class

 The code defines a class SysBatchContract for batch processing in


Dynamics AX with a data contract attribute. It has a method
parmAccountNum to set or get a vendor account number and a
validate method to ensure an account number is provided.

 To execute a batch job using an Action menu item, you can create the
item and assign your Controller class to it. When running the code,
you have the option to schedule the job by clicking on ‘Recurrence’.

 Additionally, batch jobs can be managed via System Administration →


Inquiries → Batch Jobs.
Here’s how to create System
Batch Job?
1. Click the ‘New’ button.
2. Enter the job details.
3. Set the schedule date and time.
4. Create batch tasks.
5. In the ‘Class name’ field, input the name of your Controller class.
6. Save your settings.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy