can we create an array for class objects ax 2012

can we create an dynamic objects of a class.

say I have a class AxLedgerJournalTrans can we create 10 dynamic objects for the same.

any tutorial will be appreciated.

Sure, it’s possible and if you want a classic array, it work exactly as described in the documentation (MSDN: Arrays). Here is an additional example with objects:

Tax taxArray [10];
taxArray[1] = new Tax();
taxArray[2] = new Tax();

You could also use the Array class. Nevertheless neither option is too common in AX; usually you’ll see other collection classes such as List and Set. Again, refer to the documentation for details (MSDN: Collection Classes in Microsoft Dynamics AX).

You see that the documentation contains a lot of useful information. The sooner you start using it, the better for you.

Hi Martin when i put the same line

tax taxarray[50];

it throws error “illegal base type in array”

Did I forgot to compile the job? I must have done something silly as I’m trying to answer forum questions while working at the same some time…

All right, let’s use the Array class instead:

Array taxArray = new Array(10);
taxArray.value(1, new Tax());
taxArray.value(2, new Tax());

Nevertheless as I already said, other collection classes are more common. I almost never use arrays in AX.

I looked into documentation more closely and found that “The array syntax supports only primitive data types, such as int and str. The syntax does not support classes or tables.”