Step 1 : Create a new class named DEMOSalesTableController.
class DEMOSalesTableController extends SysOperationServiceController
{
}
Step 2 : Create main method for the controller class
public static void main (Args _args)
{
DEMOSalesTableController controller = DEMOSalesTableController::construct();
controller.parmDialogCaption("Batch job caption");
controller.batchInfo().parmBatchExecute(true);
controller.startOperation();
}
Step 3 : Create the construct method for the controller class
protected static DEMOSalesTableController construct()
{
return new DEMOSalesTableController();
}
Step 4 : Create a new method for the controller class.
protected void new(IdentifierName _className = classStr(DEMOSalesTableController),
IdentifierName _methodName = methodStr(DEMOSalesTableController, processSelectedRecords),
SysOperationExecutionMode _executionMode = SysOperationExecutionMode::Synchronous)
{
super(_className, _methodName, _executionMode);
}
Step 5 : Create a new method processSelectedRecords as mentioned in the new method where all the logic for the batch job will be written.
public void processSelectedRecords(DEMOSalesTableContract _contract)
{
//Get query and demoValue from the contract class.
QueryRun queryRun = new QueryRun(_contract.getQuery());
boolean demoValue = _contract.parmDemoValue();
try
{
//Throw error if no records are selected and stop batch job execution.
if(!SysQuery::countLoops(queryRun))
{
throw error("@SYS84637");
}
while (queryRun.next())
{
//Get the current record from the query.
salesTable = queryRun.get(tableNum(SalesTable));
salesTable.selectForUpdate(true);
salesTable.DemoValue = demoValue;
salesTable.doUpdate();
}
Goto : Create a Batch Job D365 FnO
Comments
Post a Comment