HistoricalAX 2012

AX 2012: run a batch job from X++ to debug it

Run an AX 2012 batch job in CIL from a job, so you can debug it without attaching Visual Studio to the AOS.

Built on runClassMethodIL, which is removed in D365FO now that all X++ compiles to CIL.

First written
Re-read
Versions
AX 2012

In AX 2012 a batch job always runs in CIL on the batch server, which makes it awkward to debug. This note runs a batch job on demand from a job, in CIL, so you can step through it without attaching Visual Studio to the AOS instance.

The original note

In AX 2012, batch jobs always run in a CIL context. To debug a batch without attaching Visual Studio to the AOS instance, you can run it this way:

  1. Create the batch job and assign it a batch group that no batch server processes.
  2. Create this method on the BatchRun class:
server static public void runJobStaticCodeIL(RecId batchId)
{
    container ret;
    XppILExecutePermission  xppILExecutePermission;
    ;

    xppILExecutePermission = new XppILExecutePermission();
    xppILExecutePermission.assert();

    ret = runClassMethodIL(classStr(BatchRun), staticMethodStr(BatchRun, runJobStaticCode), [batchId]);

    CodeAccessPermission::revertAssert();
}
  1. Get the job ID from the batch task.
  2. Run this job:
static void batchRun(Args _args)
{
    Batch batch;
    ;
    select batch where batch.BatchJobId == 5637161890;
    BatchRun::runJobStaticCodeIL(batch.RecId);
}

Now you can debug it.

References

  • X++ language reference (Microsoft Learn): X++ compiles to .NET CIL, and “CIL helper methods such as Global::runClassMethodIL are removed”.