Business requirement: run a batch job with as dialog field value today
I you want to run a batch job daily, which has a date dialog field as input, you often don’t want the value in the date dialog to remain the same (being the value entered upon creation of the batch job), but to be equal to today (it is the day on which the batch job is run). However, you cannot enter a variable value in the dialog upon adding the batch job to the batch list in Dynamics AX.
Solution: adapt the run method of your batch class
Let’s take as example a periodic job to clean up the sales update history in Dynamics AX (Accounts receivable > Periodic > Clean up > Sales update history clean up). You can enter a Created until date to specify until which date the history should be deleted. Suppose you want to run this as a daily batch job at night, which should delete all history until today. Entering a date value of today and adding the job to the batch list wouldn’t achieve what you want. Tonight, it would delete all history until today, but tomorrow, all history would be deleted until the day before, since your Created until date would still be the same in the job in your batch list.
To solve this add following code in the run method of the involved class (in our example SalesParmCleanUp)
void run()
{#OCCRetryCount
if(this.isInBatch())
// if class is run in batch mode, set the
// createdDate dialog field equal to todays date
{
createdDate = SystemDateGet();
}
try
{
ttsbegin;
this.deleteSalesParmTables();
ttscommit;
}
…
}
How can I do this same thing if I am using a custom report that is not called from a class? The report extends ObjectRun.
I will answer my own question. I added this at the start of my fetch method:
SysReportRun sysReportRun;
;
sysReportRun = this;
if (sysReportRun.isBatchMode())
{
runDate = today();
}
Thank you Kevin
That helped me, but I had to do it this way:
sysReportRun.runbaseReport().isInBatch()
::Steffen
Post a Comment