Sunday, 2 October 2016

Create batch job through X++ code

Some flow should execute some code in batch, so you need to add a batch job for the corresponding RunBaseBatch class.

Solution



public static void scheduleBatch()
{
    BatchHeader           batchHeader;
    BatchInfo             localBatchInfo;
    YourRunBaseBatchClass yourRunBaseBatchClass;
    SysRecurrenceData     sysRecurrenceData = 
             SysRecurrence::defaultRecurrence();
    ;

    yourRunBaseBatchClass = 
        YourRunBaseBatchClass::construct();

    // retry 3 times   
    sysRecurrenceData = 
        SysRecurrence::setRecurrenceEndAfter(
                        sysRecurrenceData, 3);
    // retry after 1 minute
    sysRecurrenceData = 
        SysRecurrence::setRecurrenceUnit(sysRecurrenceData, 
                             SysRecurrenceUnit::Minute, 1);
    
    localBatchInfo = yourRunBaseBatchClass.batchinfo();
    localBatchInfo.parmGroupId("YourBatchGroupId");
    batchHeader = batchHeader::construct();
    batchHeader.addTask(yourRunBaseBatchClass);
    batchHeader.parmRecurrenceData(sysRecurrenceData);
    batchHeader.save();
}

No comments:

Post a Comment

POSTMAN D365

  Postman is useful to test the behavior of different OData class from/to D365FO. In this post we will see the steps to setup Postman with D...