Running Batch Job from X++ example code

static void TID_ExecuteBatchJobDistribution(Args _args)
    BatchHeader header;
    SysRecurrenceData sysRecurrenceData;
    Batch batch;
    BatchJob batchJob;
    RetailConnScheduleRunner _RetailConnScheduleRunner; // Class extends RunBaseBatch
    BatchInfo processBatchInfo;
    BatchRetries noOfRetriesOnFailure = 4;

    // Setup the RunBaseBatch Job
    header = BatchHeader::construct();
    _RetailConnScheduleRunner = new RetailConnScheduleRunner();
    processBatchInfo = _RetailConnScheduleRunner.batchInfo();
    processBatchInfo.parmCaption(_RetailConnSchedule.Name); // Description Batch Job
    processBatchInfo.parmGroupId('RTL'); // Batch Gorup

    // Set the recurrence data
    sysRecurrenceData = SysRecurrence::defaultRecurrence();
    SysRecurrence::setRecurrenceStartDateTime(sysRecurrenceData, DateTimeUtil::addSeconds(DateTimeUtil::utcNow(), 20)); // Set range of recurrence
    SysRecurrence::setRecurrenceUnit(sysRecurrenceData, SysRecurrenceUnit::Minute); // Set reccurence pattern
    // Set the batch alert configurations
    header.parmAlerts(NoYes::No, NoYes::Yes, NoYes::No, NoYes::Yes, NoYes::Yes);;

    // Update the frequency to run the job to every two minutes
    select forupdate batchJob
    join batch
    where batchJob.RecId == batch.BatchJobId
    && batch.ClassNumber == classnum(RetailConnScheduleRunner);

    sysRecurrenceData = batchJob.RecurrenceData;
    sysRecurrenceData = conpoke(sysRecurrenceData, 8, [10]);
    batchJob.RecurrenceData = sysRecurrenceData;

3 thoughts on “Running Batch Job from X++ example code

  1. Hola, tengo dos preguntas referente a tu contenido. 1) si quisiera colocarlo en días, o sea, que se ejecute toda la semana, en una hora especifica, como lo haría? No me queda muy claro el código. 2) Si lo quiero correr en todas las empresas que tengo en AX , como lo haria? actualmente solo me corre en una sola empresa. Muchas gracias!

    • Hello, I have two questions regarding your content. 1) If I wanted to put it in days, that is, to run all week, at a specific time, how would I do it? The code is not very clear to me. 2) If I want to run in all the companies I have in AX, how would I do it? Currently I only run in one company. Thank you very much!

  2. This updates the frequency without using SQL if your SysRecurrenceUint is Minute or Hour:
    sysRecurrenceData = SysRecurrence::defaultRecurrence();
    sysRecurrenceData = SysRecurrence::setRecurrenceStartDateTime(sysRecurrenceData, DateTimeUtil::addSeconds(DateTimeUtil::utcNow(), 20));
    sysRecurrenceData = SysRecurrence::setRecurrenceNoEnd(sysRecurrenceData);
    sysRecurrenceData = SysRecurrence::setRecurrenceUnit(sysRecurrenceData, SysRecurrenceUnit::Minute, 10);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s