The way ledger dimensions work changed drastically with the release of Dynamics AX 2012. You have probably seen the dynamic account strings, in which main account numbers are merged with ledger dimensions into one string. This is handled automatically by the user interface, but as a programmer you may have to do the same from code.
The underlying a structures are rather complex, but fortunately the utility class AxdDimensionUtil can help you with this. Assuming you have a main account ‘0001’, a dimension called “Branch” with a value of “031”, and a dimension called “Service centre” with a value of “Mumbai”, we needs to create a container with main account and all other required dimensions as Account entry pattern:
[‘MainAccountId’, ‘MainAccountId’, no. of dimensions, ‘DimensionName’, ‘DimensionValue’ , …]
dimensions = ['112050-AFS002', '0001', 2, 'Branch', 'AFS002', 'Service centre', 'Mumbai'];
AxdDimensionUtil::getLedgerAccountId takes container as parameter and creates and return ledger dimension.
the first element is actually the display value and second element is Main Account.The third element in the container is the number of dimensions, two in this case. Then the dimensions with ID followed by value.
Finally, you can pass the container to the AxdDimensionUtil::getLedgerAccountId method, which will return a ledger dimension record ID you can use as reference on the records where you need it, for example on ledger journal transactions:
The actual display of the merged account string is still handled by the user interface, but this method can help you create the underlying data without getting too gritty with the details.