Showing posts with label CIL. Show all posts
Showing posts with label CIL. Show all posts

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?




Thursday, January 3, 2013

"Execute business operations in CIL" or not?

In AX 2012, steps are taken by the development team at Microsoft to align AX IDE with .NET. That's why you regenerate the CIL after X++ code changes.

CIL obviously has its benefits like faster execution in cases of heavy logic processing.

But sometimes while testing or debugging, developers would prefer NOT to avail this option. Debugging can be cumbersome in AX 2012 as you will need to configure Visual Studio for code running in CIL. The solution is to uncheck a checkbox in Options at
Tools > Options > Development > General > Execute business operations in CIL

Now even the code which was running in CIL will now run in X++ interpreted mode, the old way.

Word of caution, this option should only be used by developers while debugging. It should ideally be checked again after work is finished.

Read more at http://msdn.microsoft.com/en-us/library/hh528509.aspx