Monday, May 6, 2013

X++ Vs CIL


In one of the assignments, I had to make a batch job using Sys operation framework.
Requirement was to create and post trade agreements, and for that I used PricePriceDiscJourService.
So I created a service class, a data contract class, a service, a query and a menu item. All standard AX objects required for a batch job to run.

The issue was that if i put all my methods/logic  in a standalone class, everything worked fine. That means records get created in all the right tables like PriceDiscAdmTrans, PriceDiscAdmtable, and PriceDiscTable. But if try to run the batch job (after CIL compile of course), it doesn’t create all the records. Some records were getting skipped, which didn’t make sense since my standalone class and the batch job class were logically speaking the same. 
I used a while(query.next()) to loop through two header/line tables and fetch records.

Now the fun part. Debugging in Visual Studio (since it’s a service you can’t debug in X++) i found that the while loop works little differently in Visual Studio than in X++. In Visual Studio, the line table's RecId gets reset even when the while loop moves to the next parent record when in fact you would expect it to be there till the cursor moves to the line record. AX, as expected, keeps the RecId value until the line table gets reassigned the next table record. My logic depended on this and it failed. Finally I changed the logic to store the table buffer in a variable and managed to get the code working.

Does anyone have a similar experience or any suggestions?




1 comment:

  1. Hi Aman,
    I can imagine your pain while investing time in debugging the code and finding the above. Nice finding. This is bit strange. I have never tried this but an advice is if you can debug any standard AX batch process using queries and try to find some more information.

    Additionally I feel this could be related to the difference in garbage collection mechanism. X++ uses deterministic garbage collection and .NET uses non deterministic garbage collection. The following links may give some idea :

    http://blogs.msdn.com/b/floditt/archive/2008/12/15/1-the-garbage-collector-in-x-and-the-clr.aspx

    http://blogs.msdn.com/b/x/archive/2012/01/13/x-deterministic-garbage-collection.aspx

    If you find anything please do update us.

    All the best,
    Rachit Garg

    ReplyDelete