Bojensen Blogs

Coding against Dimensions

The usual method of programming against a specific dimension in Ax is as follows:

salesTable.Dimension[SysDimension::Center + 1] = ‘The cost centre’;

However, this code is not technically correct. It relies on the enum value of the dimension matching the array dimension (plus 1), which is not guaranteed. If a developer follows Microsoft’s best practice guide and gives a non-sequential enum value to a new financial dimension (e.g. 100) then the code will not work.

It is better to use the following pattern when assigning to/reading from specific dimensions in X++ code. This maps the dimension to the correct array index, irrespective of the enum value.

salesTable.Dimension[Dimensions::code2ArrayIdx(SysDimension::Center)] = ‘The cost centre’;

Dimensions – Axaptapedia

Comments are closed.