Showing posts with label Batch Jobs. Show all posts
Showing posts with label Batch Jobs. Show all posts

Batch job Execution for ALL Companies



Batch job Execution for ALL Companies

void run()
{
while select crossCompany purchTable

{

    changeCompany(purchTable.DataAreaId)

{
// todo your logic
}

}

}

Support Faryal's Cusine


Batch Job Schedule X++ D365FO


Batch Job Schedule D365FO


With the following X++ sample code you can schedule a Batch job.



Sample Code




static void batchJobSchedule(Args _args)
    {
        BatchHeader objBatchheader;
        SysRecurrenceData sysRecurrenceData;
        Batch batch;
        BatchJob batchJob;
        RetailCDXScheduleRunner objRetailSchedule;
        BatchInfo objBatchInfo;
        BatchRetries noOfRetriesOnFailure = 0;
        ;

        // Setup the RunBaseBatch Job
        objBatchheader = Batchheader::construct();
        objRetailSchedule = new RetailCDXScheduleRunner();
        objBatchInfo = objRetailSchedule.batchInfo();
        objBatchInfo.parmRetriesOnFailure(noOfRetriesOnFailure);
        objBatchInfo.parmCaption("Description should be here"); // Description Batch Job
        objBatchInfo.parmGroupId('YourBatchGroup'); // Batch Gorup
        objBatchInfo.parmBatchExecute(NoYes::Yes);
        objBatchheader.addTask(objRetailSchedule);

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

        // Update the frequency to run the job to every two minutes
        ttsbegin;
        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;
        batchJob.update();
        ttscommit;
    }


Support Faryal's Cusine


Batch Job D365FO & AX 2012

            Batch Job D365FO & AX 2012

Following the below steps, You can create the batch job in simple steps.


First Create a Class and extends it with the RunBaseBatch class

BatchJob_1
Then override the description method and return the job name. it will appear on job dialog.
BatchJob_2
Now override the run method and write your logic. in my case i was updating the status from 0 to 1 in my custom table
BatchJob_3
Now override the main method and run your code like the below image
D__tuts_blog_BatchJob_4
Now Run the class by right click and select open a dialog will appear like the below image.
2016-01-29_1749.png

Support Faryal's Cusine


Virtual Fields Vs Computed Fields

  Virtual Field: A virtual field in D365FO is a field that doesn't have a direct representation in the database. It's a field that y...