Category Archives: Batch Framework

Make sure that the X++ code has been compiled to Microsoft .NET Framework CIL – AX Batch Error

I developed custom class which extend RunBaseBatch system class to run in server, After created my class and run the class though batch job, there is an error is occurred and got the following error in log.

"Unable to construct an object from the class Sample Class in the batch framework. Make sure that the X++ code has been compiled to Microsoft .NET Framework CIL, and that the constructor does not require any parameters"

After search through internet I got solution by run “Generate incremental CIL” as  displayed below


Hint: May it takes time depend on server configuration.

Debug a batch task AX 2012

Because batch tasks run in noninteractive mode and X++ executes in the common language runtime (CLR), to debug a batch task, you have to perform additional steps to configure the AOS and the Visual Studio debugger, in addition to setting up breakpoints.
First, configure the AOS for batch debugging. This is necessary for two reasons.
1-  The AOS modifies the X++ assembly to disable Just-In-Time (JIT) optimizations in the CLR. This is necessary to enable variables and object contents to be viewed and analyzed in the debugger.
2- The AOS produces source files containing the X++ code under the server BinXppILSource folder. You can open these files in Visual Studio to set breakpoints and perform common tasks, such as step ping into and step ping over.
Configure AOS for batch debuggingUse the Microsoft Dynamics AX Server Configuration Utility (see Figure below) to configure the AOS for batch debugging. The utility is available on the computer on which you installed the AOS. To do this, perform the following steps:
1. Open the Microsoft Dynamics AX Server Configuration Utility. Click Start > All Programs > Administrative Tools > Microsoft Dynamics AX 2012 Server Configuration.
2. Select the Enable Breakpoints to Debug X++ Code Running on This Server check box.
3. Click OK to close the utility, and then restart the AOS.
Configure Visual Studio for debugging X++ in a batch
To configure Visual Studio for batch debugging, attach to the AOS process Ax32Serv.exe by following these steps:
1. In Visual Studio, on the Debug menu, click Attach To Process.
2. When the Attach To Process dialog box opens (see Figure below), click Select to select Managed (v4.0) code, and then select the following check boxes:
• Show Processes From All Users
• Show Processes In All Sessions
3. Click Ax32Serv.exe, and then click Attach.
Clear the Enable Just My Code (Managed Only) check box, and then click OK.
After you complete these steps, you can open the X++ source code from the BinXppILSource folder on the server and set breakpoints.

Manage batch jobs AX 2012

After you create and schedule a batch job, you might want to check its status, review its history, or cancel it. The following sections describe some of the most common management tasks associated with batch jobs.

View and change the batch job status
The Batch Job list form provides a snapshot view of the current state of batch jobs. The list displays the progress and the status of running and completed jobs. It also displays any jobs that are scheduled to start soon.
You can change the status of a batch job by selecting the batch job in the list and then following these steps:
1. Click Functions, and then click Change Status.
2. In the Select New Status dialog box, select a new status for the job. For example, if the status is Waiting, you can temporarily remove the batch job from the waiting list by changing the status to Withhold.

Tip If a job exits with a status of Error/Ended and you want to rerun the job, change its status to Waiting. The job will automatically be picked up by the server for execution.

You can cancel a batch job by changing its status to Canceling. Tasks in the Waiting or Ready state are changed to Not Run; currently executing tasks are interrupted, and their status is changed to Canceled.

Control the maximum retries
If an AOS fails because of an infrastructure failure or a power outage while a batch task is executing, the batch framework has the built-in capability to retry tasks after the AOS is restarted. Any tasks that were left in an executing state, and that have not reached the maximum retry limit, are changed to the Ready state and will run shortly after the failure.

Tip If you create custom tasks and want to enable retries, design the task so that it is idempotent—that is, it can be executed multiple times without unexpected consequences.

You can modify the Maximum Retries attribute for each batch task on the General tab. By default, the value is set to 1; when the Actual Retries field on the Update tab exceeds the maximum number of retries, the batch task fails. When this happens, the recurrence that is set for the batch job is not honored, and the status of the batch job is set to either Success or Error.

Review the batch job history
You can view a history of all batch jobs that have finished running in the Batch Job History form at System Administration > Inquiries > Batch Job History. This form displays detailed information about the status of the jobs, including any messages encountered while the batch job was running.

You can also view the logs for each batch job as follows:
■ To view log information for an entire batch, select a batch job, and then click Log.
■ To view log information for individual tasks, select a batch job, and then click View Tasks. In the Batch History list form, select a task, and then click Log.

Tip In the batch job settings, you can specify when log information is written to the history tables: Always (the default), On Error, or Never. Use On Error or Never to save disk space for batch jobs that run constantly. This option is located on the General tab of the
Batch Job form.

Inside Dynamics AX 2012 Book

Manage batch execution AX 2012

The final step in implementing a batch job is to manage the execution process. Before a batch job can be executed on an AOS instance, you must configure the AOS instance as a batch server and set up the batch groups that tell the system which AOS instance should execute the job.
In addition to these initial configuration tasks, you’ll likely need to manage the batch tasks and jobs: checking status, reviewing history, and sometimes canceling a batch job. You’ll probably also need to debug a batch task at some point.

The following sections describe how to configure an AOS instance as a batch server and set up batch groups, and the next 2 posts will describe manage batch jobs and debug a batch task.

Configure the batch server
You can configure an AOS instance to be a batch server, including specifying when the batch server is available for processing and how many tasks it can run, by using the Server Configuration form.
The Server Configuration form is located at System Administration > Setup > System > Server Configuration.
Note that the first AOS instance is automatically designated as a batch server, but you can configure additional AOS instances manually as batch servers.

Tip Use multiple batch servers to enable parallel processing and increase processing throughput.

1. In the Server Configuration form, select a server in the left pane.
2. Select the Is Batch Server check box to enable batch processing on the server, as shown in Figure below.


3. On the Batch Server Schedule FastTab, click Add to enter a new schedule. Enter the maximum number of batch tasks that can be run on the AOS instance at one time. The server continues to pick up tasks from the queue until it reaches its maximum.
4. Enter a starting time in Start Time and an ending time in End Time to specify the time window in which the server processes batch jobs. Press Ctrl+N to enter an additional time window.

Tip It’s a good idea to exclude a server from batch processing when it is busy processing regular transactions. You can set server schedules so that each AOS instance is available for user traffic during the day and batch traffic overnight. Keep in mind that if the server
is running a task when its batch processing availability ends, the task continues running to completion. However, the server doesn’t pick up any more tasks from the queue.

Create a batch group
A batch group is a logical categorization of batch tasks that lets a user (typically a system administrator) determine which AOS instance runs the batch task. This section describes how to create a batch group so that it can be assigned to a specific server for execution. The first step is to create batch groups by using the Batch Group form at System Administration > Setup > Batch Group.

To create a batch group, press Ctrl+N in the Batch Group form, and then type a name and description for the batch group. The Batch Group form is shown in below


Note By default, the system contains an empty batch group that can’t be removed. This is a default batch group for tasks that are not explicitly assigned to a group.

After you create batch groups, assign each group to a server as follows:
1. In the Server Configuration form (shown in Figure below), click the Batch Server Groups FastTab.
The Selected Groups list shows the batch groups specified to run on the selected server.
2. In the Remaining Groups list, select a group, and then click the left arrow button to add this group to run on the selected server.


Note  you can assign each group to a server using Batch Servers in Batch Group form

Imparted from Inside Dynamics AX 2012 Book

Create and execute a batch job AX 2012

Microsoft Dynamics AX 2012 includes numerous batch jobs that perform operations such as generating reports, creating sales invoices, and processing journals. However, in several situations, organizations need to create their own batch jobs. The batch framework provides full flexibility in the types of jobs that you can create. This section walks you through the following steps, which are required for creating, executing, and managing a batch job:
1. Create a batch-executable class.
2. Create a batch job and define the execution schedule.
3. Configure a batch server and create a batch group. (It be will explained in another post)
4. Manage the batch job. (It will be explained in another post)
Create a batch-executable class
The first step in developing a batch job is to define a class that can be executed as a batch task. Many classes included with Microsoft Dynamics AX 2012 are already enabled for batch processing. You can also design a batch-executable class, as shown in the following example:
public class ExampleBatchTask extends RunBaseBatch

To run as a batch task, a class must implement the Batchable interface. The best way to implement the interface contract is to extend the RunBaseBatch abstract class, which provides much of the necessary
infrastructure for creating a batch-executable class. An alternative is to use the SysOperation framework, which provides additional advantages compared to extending the RunBaseBatch class. Will post more information about the SysOperation framework Later.
Table below describes the methods that must be implemented when you extend the RunBaseBatch class. The following sections describe these methods in more detail.

Method Description
run Contains the core logic for your batch task
pack Serializes the list of variables used in the class
unpack Deserializes the list of variables used in the class
canGoBatchJournal Determines whether the class appears in the Batch Task form

run methodYou implement the core logic of your batch class in the run method. The run method is called by the batch framework for executing the task defined within it. You can run most of the X++ code in this method; however, there are some limitations on the operations that you can implement. For example, you can’t call any client logic or dialog boxes. However, you can still use the Infolog class. All Infolog and exception messages are captured when the batch class executes, and they are stored in the batch table. You can view these later in the Batch Job form or the Batch Job History form, both of which are located under System Administration > Inquiries > Batch Jobs.

Note If an error message is written to the Infolog, it does not mean that the task has failed; instead, an exception must be thrown to indicate the failure
pack and unpack methods
A class that extends RunBaseBatch must also implement the pack and unpack methods to enable the class to be serialized. When a batch task is created, its member variables are serialized by using the pack method and stored in the batch table. Later, when the batch server picks up the task for execution, it deserializes class member variables by using the unpack method. So it’s important to provide a correct list of the  variables that are necessary for class execution. If any member variable isn’t packable, then the class can’t be serialized and deserialized to the same state.
The following example shows the implementation of the pack and unpack methods:
public container pack()
                         return [#CurrentVersion,#CurrentList];
public boolean unpack(container _packedClass)
                        Version version = RunBase::getVersion(_packedClass);
                        switch (version)
                                  case #CurrentVersion:
                                                         [version,#CurrentList] = _packedClass;
                                                        return false;
                     return true;

The #CurrentList and #CurrentVersion macros that are referenced in the preceding code must be defined in the class declaration. Using a macro simplifies the management of variables in the class. If you add or remove variables later, you can manage the list by modifying the macro. The #CurrentList macro holds a list of the class member variables to pack, as shown here:
canGoBatchJournal method
When a system administrator creates a new batch task by using the Batch Task form, the canGoBatchJournal method determines whether the batch task class appears in the list of available classes. For an example of how to use canGoBatchJournal.

Create a batch jobThe second step in developing a batch job is to create the batch job and add batch tasks. You can create a batch job in three ways:
■ By using the dialog box of a batch-enabled class
■ By using the Batch Job Designer form
■ By using the Batch API (It be will explained in another post)
The method you use depends on the degree of flexibility that you need and the complexity of the batch job. To create a simple batch job, consisting of a single task with no dependencies, you typically use the dialog box of a batch-executable class; to create a more complex batch job, consisting of several tasks that might have dependencies, use the Batch Job form; to create a highly complex or very large batch job, or one that needs to be integrated with other business logic, use the Batch API.
The following sections provide an example of using each method.
Create a batch job from the dialog box of a batch-executable class
The simplest way to run a batch-executable class as a batch job is to invoke the class by using a menu item. A menu item that points to a batch-executable class automatically opens a dialog box that lets
the user create a batch job. On the Batch tab of the dialog box, select the Batch Processing check box, as shown for the Change based alerts class in Figure below. When you select Batch Processing and click
OK, a new batch job with the task that represents the batch-executable class is created. The batch job then runs asynchronously at the date and time you specify. You can also set up recurrences or alerts
for the job by clicking the appropriate button on the right side of the dialog box. You can also specify the batch group for the task by using the drop-down list.

Create a batch job by using the Batch Job formYou can open the Batch Job form from several places. For example, you can open it by clicking Batch Jobs from System Administration > Inquiries > Batch Jobs or by selecting My Batch Jobs (for users) from Home > Inquiries > My Batch Jobs. Both menu items open the same form, but the information that is presented in the form differs, depending on the menu item that you use to open it. Depending on how you open the form and your level of access, you can view either the batch jobs that you have created or all batch jobs that are scheduled in the system.
Press Ctrl+N to create a new batch job, and then enter the details for the job in the grid or on the General tab: a description, and the date and time at which you want the job to start. You can also set up recurrence for the batch job by clicking Recurrence on the menu bar, and then entering a range and pattern for the recurrence.
Note If you don’t enter a date and time, the current date and time are entered automatically.
figure below show Batch Job Form
Batch tasks form
To create a task, do the following:
1. Press Ctrl+N to create the task.
2. In Task Description, enter a description of the task.
3. In Company Accounts, select the company in which the task runs.
4. In Class Name, select the process that you want the task to run. Classes appear in a lookup list containing all available batch-enabled classes. The lookup list appears only if the CanGoBatchJournal property is enabled.
5. In Batch Group, select a batch group for the task if necessary.
6. Save the task by pressing Ctrl+S.
7. Specify class parameters if necessary. As mentioned in previous sections, each batch task represents
a batch-executable class. Sometimes you need to set up parameters for that class.
For example, you might need to specify posting parameters for invoice posting. To do that, click Parameters on the menu bar in the Batch Tasks form. A dialog box specific to the selected class is displayed.
Note If you are creating a custom batch class, you must design the parameters form manually. If you implement a batch based on the SysOperation framework, this process is highly simplified. After you specify the necessary parameters and click OK, the class parameters are packed and saved in the Batch table and then are restored when the class executes.
8. Set up dependencies or advanced sequencing between tasks, if necessary.

After you create the batch job and add tasks to it, you can use the Batch Tasks form to define dependencies between the tasks. If no dependencies or conditions are defined within a job, the batch server automatically executes the tasks in parallel. (To configure the maximum number of parallel tasks, use the Maximum Batch Threads parameter in the Server Configuration form.)
If you need to use advanced sequencing to accommodate your business process flow, you can use either the Batch Tasks form or the Batch API. You can use these tools to construct complex dependency
trees that let you schedule batch jobs tasks in parallel, add multiple dependencies between batch tasks, choose different execution paths based on the results of the previous batch task, and so on.
For example, suppose that the job, JOB1, has seven tasks: TASK1, TASK2, TASK3, TASK4, TASK5, TASK6, and TASK7, and you want to set up the following sequence and dependencies for it:
■ TASK1 runs first.
■ TASK2 runs on completion (Ended or Error) of TASK1 (regardless of the success or failure of TASK1).
■ TASK3 runs on success (Ended) of TASK2.
■ TASK4 runs on success (Ended) of TASK2.
■ TASK5 runs on failure (Error) of TASK2.
■ TASK6 runs on failure (Error) of TASK3.
■ TASK7 runs on success (Ended) of both TASK3 and TASK4.
dependency tree for JOB
To define these task dependencies and to tell the system how to handle them, select a child task—for example, TASK2—from the preceding list, and then do the following:
1. In the Batch Tasks form, click in the Has Conditions grid, and then press Ctrl+N to create a new condition.
2. Select the task ID of the parent task, such as TASK1.
3. Select the status that the parent task must reach before the dependent task can run. For example, TASK2 starts when the status of TASK1 becomes Ended or Error.
4. Press Ctrl+S to save the condition.
5. If you enter more than one condition, and if all conditions must be met before the dependent task can run, select a condition type of All.
Alternatively, if the dependent task can run after any of the conditions are met, select a condition type of Any.
You can use the Batch Tasks form to define how the system handles task failures. To ignore the failure of a specific task, select Ignore Task Failure for that task on the General tab. If you select this option, the failure of the task doesn’t cause the job to fail. You can also use Maximum Retries to specify the number of times a task should be retried before it fails.
Imparted from Inside Dynamics AX 2012 Book.


Get every new post on this blog delivered to your Inbox.

Join other followers:

error: Content is protected !!