Hello experts,
I am new to AX, and this community. I need to do some testing within AX2021.
I am trying to create multiple tasks within a batch group through the API. Everything is well, after compile, and click the play button; group is created with tasks within.
However, now, I am hard coding the tasks creation part, i.e. if i want to create 2 tasks, i need to duplicate the code twice and change the variables.
I tried to use for loop, but the result is same as without the for loop.
The below is my code with for loop:
private static void main (Args _args)
{
BatchHeader batchHeader1;
BatchInfo batInfo1;
RunBaseBatch batchTask1;
RunbaseBatch batchTask2;
int i;
;
for (i = 1; i<20; i++)
{
// create batch header
batchHeader1 = BatchHeader::construct();
// create and add batch tasks
batchTask1 = new WorkCalendarDelete();
batchTask1.Caption();
batchHeader1.addTask(batchTask1);
batInfo1 = batchTask1.batchInfo();
batInfo1.parmGroupId("CAUBGRP");
batInfo1.ignoreOnFail(true);
}
//
batchTask2 = new AifGatewaySendService();
batchTask2.Caption();
batchHeader1.addTask(batchTask2);
//Give the batch job a name
batchHeader1.parmCaption("cau1232");
// save batch job in the database
batchHeader1.save();
}
Thank you so much.
Charlie