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:
- Create the batch job and assign it a batch group that no batch server processes.
- Create this method on the
BatchRunclass:
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();
}
- Get the job ID from the batch task.
- 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::runClassMethodILare removed”.