Wednesday, April 1, 2009

Range of RecID in an AX Table


In every new table the recID (surrogate key) range starts from the no. 5637144576 and since it is int64 so it goes upto 2^63 (9223372036854775808). It also signifies an important fact that we can't have unique recIDs accross different tables.

Monday, December 22, 2008

Manipulating a form datasource in a class.

It is possible to pass a datasource bound to a grid in a class and then iterate like a query. In this post, I'll giving some code snippets to work with form datasource in some other object like classes.

Step 1:
Your method or constructor of the class should be able to recieve FormDataSource type object. This class is used to handle a form datasource. You may send your datasource to this class' object by other means like calling parm methods.


public void printOpenTransactions(FormDataSource _formDataSource)
{
}


Step 2:
Create a Query and QueryRun Objects by calling query() method of the datasource

Query query = _formDataSource.query();
QueryRun queryRun = new QueryRun(query);

Step 3:
Iterate through each record in datasource and get the table buffer to do further processing.

while (queryRun.next())
{
TableBuffer buffer = queryRun.get(tablenum(TableBuffer));
// do processing on buffer
}


That's it.

Friday, November 14, 2008

Separate workspace for development in AX 2009


Finally Microsoft has come up with different separate wrokspace for developers of AX. If you have access to the latest build of AX 2009, you'll notice the absence of all development related tools. Only AOT can be accessed by clicking Ctrl + D (I think they'll move it away too). For doing all kind of development and technical things you need to press Ctrl+Shift+W to switch to the different and relatively simple UI. The good thing is you are now got rid of all of the navigation panes of applicaton and can focus now on more physical stuff.

Monday, June 16, 2008

How to check configuration key in code?

Q: How can I check whether the particular configuration key is enabled or not in the code at runtime?

A: Simple, you can use the function isConfigurationkeyEnabled(configurationkeynum(LedgerBasic)) anywhere in the code. It returns a boolean type.

Thursday, September 20, 2007

Test Driven Development

A good link to know about tools and theory of TDD (Test Driven Development)
http://www.testdriven.com

Setting a table field mandatory doesn't allow zero to enter

In Dynamics AX if you set any integer or real type field of a table mandatory, then it would not allow 0 to enter in that field. Whenever a user enters 0 and move to the next field the following infolog message appears.

Field 'fieldname' must be filled in.

But if you don't like this error message and need something else to display then provide a check in the code. For example by overriding the validateField() method.

Tuesday, September 11, 2007

Setting up test data for unit Testing

We should make sure that the unit tests should be independent of data as much possible. For this purpose the Unit Test framework provided by David Pokluda also talks about two very important methods. setUp() and tearDown(). These are very important methods provided by all unit testing framework designed for any technology. setUp() deals with all those operations that needs to be performed in the beginning of all testing and tearDown() should be overridden clear all those things.
For example you want to write unit test for some calculateTotalcost() method written on some table TransactionDetails. You want to setup test data in the table. Following can be the code sample.

class MyTest extends SysTestCase
{
public void testMethod()
{
TransactionDetails transDetails;
;
transDetails.transId = '01';

this.assertsEqual(500,transDetails.calculateTotalcost());
}

void setUp()
{
TransactionDetails transDetails;
;
transDetails.transId = '01';
transDetails.Quantity = 2;
transDetails.Price = 250;
transDetails.insert();
}

void tearDown()
{
TransactionDetails transDetails;
;
transDetails.transId = '01';
transDetails.delete();
}
}

So, we are actually setting the test data in setup method and then calling assertEquals on that. Finally we are deleting the test record.