web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Creating multiple tasks within a BatchGroup

(0) ShareShare
ReportReport
Posted on by 145

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

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    DG Profile Picture
    1,226 on at
    RE: Creating multiple tasks within a BatchGroup

    Move the header initialization code before the start of loop. That should sort it out.

  • charlieau Profile Picture
    145 on at
    RE: Creating multiple tasks within a BatchGroup

    Got it, thanks a lot!

  • Verified answer
    Ihab Barghout Profile Picture
    605 on at
    RE: Creating multiple tasks within a BatchGroup

    Dear Charlieau,

    It looks like you are reconstructing your batch header inside the loop.

    // create batch header

    batchHeader1 = BatchHeader::construct();

    so it is re initializing on each iteration. try moving it outside the loop statement.

    Regards,

  • charlieau Profile Picture
    145 on at
    RE: Creating multiple tasks within a BatchGroup

    Hi DG,

    My problem is, with this code, i am still only have 2 tasks in the batch job. But what I am expecting is, i should have 21 tasks.

    20 WorkCalendarDelete , and 1 AifGatewaySendService()  , that is what I want to achieve.

    However, i don't want to copy and paste 20 times, and only changing the number. I wonder if there is a way i can write it better.

    Thanks. :)

    Charlie

  • DG Profile Picture
    1,226 on at
    RE: Creating multiple tasks within a BatchGroup

    Hi Charlie,

    I see what you are trying to do. But what is your question?

    Regards,

    Deepak

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Syed Haris Shah Profile Picture

Syed Haris Shah 9

#2
Mea_ Profile Picture

Mea_ 4

#3
Community Member Profile Picture

Community Member 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans