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

Thursday, November 10, 2011

Debug X++ code in a Batch Server in AX 2009

Hi there!

Today I would like to discuss how to debug X++ code in a batch server. One of the common scenarios in AX development is the debugging of X++ code in the client.

For example, if you want to debug the SalesFormLetter class after posting either a Packing Slip or an Invoice, you just would go to the AOT > Classes>SalesFormLetter look for the method you want to debug and add a breakpoint. Simple!

In AX 2009, however, we have the ability to run Batch jobs directly on the server (unlike prior versions (i.e. 3.5)). The problem is that to accomplish this, we have to configure a few things.

The following are the steps to accomplish debugging X++ code in a batch server. The example is going to be using the SalesFormLetter class run method.

NOTE: Please use a Development or Test environment to try these steps.

1- Open the Client Configuration Utility and Click the Manage button. Choose Create New Configuration.

2- Give it a name. (I have chose Debug2713)



3- Set the server name, instance name and port (the default for the first instance of AX will be 2712. If you have more than one instance make sure you have the right port. In my case the AX second instance is 2713)



4- Go to the developer tab and check the both "Enable user breakpoints to debug in the business connector" and "Enable global breakpoints to debug code running in the business connector or client" check boxes.



5- Now open the Server Configuration File and Click the Manage button. Choose Create New Configuration. Give it a name (i.e. Debug)

6- Set the application file location and the alternate bin directory and the Application instance. In addition, check both the "Enable breakpoints to debug X++ code running on this server" and "Enable global breakpoints to debug X++ code running in batch jobs" check boxes.



7- Click the Database Connection tab and set both the server name and database name.





8- Open the AR module and go to Periodic > Clean Up > Sales update history clean up

9- Choose the Executed Clean Up option and a date and click OK.



10- Open the AOT, go to Classes and look for the SalesFormLetter class. Open the class and look for the Run method and place a breakpoint anywhere in the code.



12- Open the AX 2009 debugger



12 - Go to AR > Common Forms and open the Sales Order Details form. Choose an Open Order and click the Post button. Choose Packing Slip (i.e.)

13 - The SalesEditForm will open. Click the Batch button and set the batch.



14- After clicking the OK button you should see the following message




If you want to check the status of your batch you can go to Basic > Inquiries >Batch Job. Your scheduled job should be in there. Wait a few minutes and the debugger should open at the breakpoint you inserted before.


NOTE: Sometimes you will have to restart the AOS service when the debugger does not open and your job has already executed. In addition, you MUST have a batch group setup.

Take Care!

Thursday, October 27, 2011

AX 2009 Workflow - Run batch jobs through a Job

When working with Workflows, sometimes  have encountered a situation where my workflow item just don't run.
This might be due to a problem on the Batch Server. To test (run) the workflow mimicking the batch server we can write the following job.
static void workflowJobs(Args _args)
{
    SysWorkflowMessageQueueManager  queueManager;
    WorkflowWorkItemDueDateJob      workItemDueDateJob;
    ;

    queueManager = SysWorkflowMessageQueueManager::construct();
    queueManager.run();
    workItemDueDateJob = new WorkflowWorkItemDueDateJob();
    workItemDueDateJob.run();
}

Another alternative is to go to AOT > Forms > Tutorial_WorkflowProcessor and click the start button.

Monday, March 28, 2011

Find AOT classes through X++

Today I needed to implement a job that existed my company's old version of AX into AX 2009. In the Old Axapta I went to Basic > Batch List to find the name of the job and/or the date it was created.

Then I went to the AOT > Data Dictionary > Tables > Batch and I opened the table by using the table browser and I saw that the Class ID for this particular Job was 40144.

Then I created a new job and I wrote the following code:


static void ClassNames(Args _args)
{
    DictClass   dictclass;
    ;
   
    dictclass = new DictClass(40144);
    info(dictclass.name());
}



The info log showed me the name of class that is run by the AX Job. From there I just created a new batch record to run it every night.