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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

x++ Batch Dependencies not working

(0) ShareShare
ReportReport
Posted on by

We're running Microsoft Dynamics AX 2012 R3. 

I've got the following code where I'm running a "Move to Bay Door" batch job followed by a "Confirm Shipment" batch job.  Then, if multiple "All work" Work ID's have been selected, I want each "Move to Bay Door" to be dependent on the "Confirm Shipment" completing before the next "Move to Bay Door" runs. 

    //create batch header
    batchHeader = BatchHeader::construct();
    batchHeader.parmCaption("Move to Baydoor & Confirm Shipment");

    while(whsWorkTable)
    {
        bayDoorBatchTask = UT_AP_WHSWorkFinalizeComplete::construct(whsWorkTable.WorkId);
        //add the baydoor batch tasks to a 'set' for processing later
        setBayDoors.add(bayDoorBatchTask);
        //add the batch tasks to the batch header
        batchInfo = bayDoorBatchTask.batchInfo();
        batchInfo.parmCaption(strFmt("Move to Bay Door for WorkId %1",whsWorkTable.WorkId));
        batchInfo.parmGroupId("AOS2");
        batchHeader.addTask(bayDoorBatchTask);
        batchHeader.addRuntimeTask(bayDoorBatchTask,BatchHeader::getCurrentBatchTask().RecId);

        confirmShipBatchTask = UT_AP_WHSWorkShipConfirm::construct(whsWorkTable.WorkId, true, false);
        //add the batch tasks to the batch header
        batchInfo = confirmShipBatchTask.batchInfo();
        batchInfo.parmCaption(strFmt("Confirm Shipment for WorkId %1",whsWorkTable.WorkId));
        batchInfo.parmGroupId("AOS2");
        batchHeader.addTask(confirmShipBatchTask);
        batchHeader.addRuntimeTask(confirmShipBatchTask,BatchHeader::getCurrentBatchTask().RecId);

        //define a dependency between the Move to Bay Door and the Confirm Shipment tasks
        batchHeader.addDependency(confirmShipBatchTask, bayDoorBatchTask, BatchDependencyStatus::Finished);

        whsWorkTable = multiSelectionHelper.getNext();
    }

    // Create dependencies between bayDoor batches
    sBayDoors = setBayDoors.getEnumerator();
    sBayDoors.movenext();
    bayDoorBatchTask = sBayDoors.current();  //1st bay door task

    while (sBayDoors.movenext())
    {
        bayDoorBatchTask2 = sBayDoors.current(); //2nd bay door task
        // Now define a dependency between the Move to Bay Doors
        batchHeader.addDependency(bayDoorBatchTask2, bayDoorBatchTask, BatchDependencyStatus::FinishedOrError);
        bayDoorBatchTask = bayDoorBatchTask2;  //Assign 2nd task to 1st task and repeat
    }

    //save the batch
    batchHeader.save();

The Results:

Ended

Move to Bay Door for WorkId 0746820

2/7/2019

01:18:03 pm

2/7/2019

01:20:17 pm

No Dependencies

Ended

Confirm Shipment for WorkId 0746820

2/7/2019

01:20:17 pm

2/7/2019

01:23:57 pm

Dependencies

Ended

Move to Bay Door for WorkId 0746824

2/7/2019

01:20:17 pm

2/7/2019

01:28:23 pm

Dependencies

Ended

Confirm Shipment for WorkId 0746824

2/7/2019

01:28:25 pm

2/7/2019

01:34:21 pm

Dependencies

So my 2nd "Move to Bay Door" started before my 1st "Confirm Shipment" ended.  My dependency between the "Move to Bay Door" and the "Confirm Shipments" seems to be working just fine, but my dependency between "Move to Bay Doors" doesn't seem quite right.   

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    chessdr Profile Picture
    on at

    I was able to figure this one out, finally!  I was putting the dependencies between the two "Move to Bay Door" tasks.  I needed the second "Move to Bay Door" tasks dependent on the first "Confirm Shipment" task finishing!  I had to save off the "Confirm Shipment" tasks into a 'set', then I started with the second "Move to Bay Door" and made a dependency with the first "Confirm Shipment" and it worked great.  

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans