programming4us
         
 
 
Applications Server

Microsoft Dynamic AX 2009 : The Batch Framework (part 4) - Creating a Batch Job - Using the Batch API

- How To Install Windows Server 2012 On VirtualBox
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire
7/8/2013 9:03:28 PM

4.3 Using the Batch API

For advanced scenarios requiring complex or large batch jobs, such as inventory closing or data upgrades, the batch server framework provides an X++ API that enables developers to create or modify batch jobs, tasks, and their dependencies as needed as well as to dynamically create run-time batch tasks on the fly. This flexible API helps automate task creation and integrate batch processing into other business processes. It can also be useful when your batch job or task requires some additional logic.

Create a Batch Job

First, you have to create a Batch Job instance class named BatchHeader.

        batchHeader = BatchHeader::construct();


Note

When you construct an instance of the BatchHeader class, no batch jobs are physically created in the system yet. All operations are performed in memory until you call the batchHeader.save function, which saves your changes in the database.


You can also construct a BatchHeader object for an existing BatchJob by providing an optional batchJobId parameter to the construct method, as shown here.

     batchHeader = BatchHeader::construct(this.parmCurrentBatch().BatchJobId);

					  


The BatchHeader class allows you to access and modify most BatchJob parameters using parm methods. For example, you can set up recurrence and alerts for your batch job as shown in the following example.

// Set the batch recurrence
sysRecurrenceData = SysRecurrence::defaultRecurrence();
sysRecurrenceData = SysRecurrence::setRecurrenceStartDateTime(sysRecurrenceData,
DateTimeUtil::utcNow());
sysRecurrenceData = SysRecurrence::setRecurrenceNoEnd(sysRecurrenceData);
sysRecurrenceData = SysRecurrence::setRecurrenceUnit(sysRecurrenceData,
SysRecurrenceUnit::Hour, 1);
batchHeader.parmRecurrenceData(sysRecurrenceData);
// Set the batch alert configurations
batchHeader.parmAlerts(NoYes::No, NoYes::Yes, NoYes::No, NoYes::No, NoYes::No);

					  


Add a Task to the Batch Job

After you create a batch job using the Batch API, you can add tasks to it by calling the addTask method. The first parameter for this method is an instance of a batch-enabled class that will be scheduled for execution as a batch task.

void addTask(Batchable batchTask,
 [BatchConstraintType constraintType])


Another way to create a task is to use the method addRuntimeTask, which creates a dynamic batch task. It exists only for the current run, and it gets copied into the history tables and deleted at the end of the run. It copies settings such as batch group and child dependencies from the inheritFromTaskId task.

void addRuntimeTask(Batchable batchTask,
RecId inheritFromTaskId,
[BatchConstraintType constraintType])


Define Dependencies Between Tasks

After you add tasks, you can use the Batch API to specify any dependencies between them. The BatchHeader class provides the method addDependency, which you can use to define a dependency between the tasks batchTaskToRun and dependsOnBatchTask.

The optional parameter batchStatus allows you to specify the type of the dependency. By default a dependency of type BatchDependencyStatus::Finished is created, which means that the task starts execution only if the task which it depends on finishes successfully. Other allowed options are BatchDependencyStatus::Error (the task will start execution if the preceding task finished with an error) and BatchDependencyStatus::FinishedOrError (the preceding task finished processing with any status result).

public BatchDependency addDependency(
    Batchable batchTaskToRun,
    Batchable dependsOnBatchTask,
   [BatchDependencyStatus batchStatus])


Save a Batch Job

After you have finished defining the batch job, it’s important to call the batchHeader.save method. Under the hood, the save method inserts records into the BatchJob, Batch, and BatchConstraints tables where the batch server can automatically pick them up for execution. However, you must run client tasks manually by using the Set Up Batch Processing form (from the Dynamics AX basic module, click Periodic\Batch\Processing).

Example of a Batch Job

The following example shows how you can create a batch job and two batch tasks using the Batch API.

static void ExampleSchedulingJob (Args _args)
{
    BatchHeader       batchHeader;
    RunBaseBatch batchTask;
    ;
    // create batch header
    batchHeader = BatchHeader::construct();
       // create and add batch tasks
    batchTask1 = new ExampleBatchTask();
    batchTask1.parmCaption("Example batch job 1");
    batchHeader.addTask(batchTask1);

    batchTask2 = new ExampleBatchTask();
    batchTask2.parmCaption("Example batch job 2");
    batchHeader.addTask(batchTask2);
    // add dependencies between batch tasks
          batchHeader.addDependency(batchTask1, batchTask2);
       // save batch job in the database
    batchHeader.save();
}
Other -----------------
- Using Non-Windows Systems to Access Exchange Server 2007 : Terminal Server Client for Mac
- Using Non-Windows Systems to Access Exchange Server 2007 : Configuring and Implementing Entourage for the Mac
- Microsoft Lync Server 2010 : Planning for Deploying External Services - High Availability
- Microsoft Lync Server 2010 : Planning for Deploying External Services - Firewall Configuration (part 2)
- Microsoft Lync Server 2010 : Planning for Deploying External Services - Firewall Configuration (part 1)
- Microsoft Lync Server 2010 : Planning for Deploying External Services - Edge Server Considerations
- Microsoft Dynamic GP 2010 : Receivables Management (part 4) - Sales e-mail settings, Customers
- Microsoft Dynamic GP 2010 : Receivables Management (part 3) - Customer classes
- Microsoft Dynamic GP 2010 : Receivables Management (part 2) - Receivables Setup Options, Sales Territories, Salespeople
- Microsoft Dynamic GP 2010 : Receivables Management (part 1) - Receivables Management Setup
- Microsoft Dynamic GP 2010 : Payables Management (part 3) - Purchasing E-mail setup, Vendors
- Microsoft Dynamic GP 2010 : Payables Management (part 2) - Payables Setup Options, Vendor classes
- Microsoft Dynamic GP 2010 : Payables Management (part 1) - Payables Management Setup
- Microsoft Dynamic GP 2010 : Bank Reconciliation
- Microsoft Dynamic GP 2010 : General Ledger
- Using Non-Windows Systems to Access Exchange Server 2007 : Mac OS X Mail
- Using Non-Windows Systems to Access Exchange Server 2007 : Outlook Express
- Using Non-Windows Systems to Access Exchange Server 2007 : Understanding Non-Windows–Based Mail Client Options
- Microsoft Dynamics AX 2009 : The Application Integration Framework (part 8) - Consuming Web Services from Dynamics AX
- Microsoft Dynamics AX 2009 : The Application Integration Framework (part 7) - Sending One-Way Requests from Dynamics AX
 
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us
Video Tutorail Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS
Celebrity Style, Fashion Trends, Beauty and Makeup Tips.