Create financial dimension combination in AX2012 from code

I found this excellent post from Becky Newell about creating financial dimension combinations under X++.
===================
The first and best way to create dimension combinations is to use the class and method DimensionServiceProvider\buildDimensionStorageForLedgerAccount.  The buildDimensionStorageForLedgerAccount method takes a
LedgerAccountContract class.  In the LedgerAccountContract class there are two parm methods, parmMainAccount and parmValues.  The parmMainAccount method takes the MainAccount like ‘10060’ and the parmValues method takes a list of the other dimension values you want to set.  More specifically the parmValues method takes a list of classes.  The classes are of type DimensionAttributeValueContract.  On the DimensionAttributeValueContract class you set two
methods, parmName and parmValue.  For example, ‘Department’ for the name and ‘10’ for the value. Build up a list of DimensionAttributeValueContract classes for each dimension you want to specify and then pass the list to the parmValues method on the LedgerAccountContract class.  Once you have the LedgerAccountContract built up send it to the DimensionServiceProvider\buildDimensionStorageForLedgerAccount.

Optionally you can use a utility method in AX in AxdDimensionUtil\getLedgerAccountId.  This one is not as nice as buildDimensionStorageForLedgerAccount because it takes a container instead of a class (with known types).  Here’s an example of the method in AX:
container myContainer = ["110180-USAA", “110180”, 1, "Country", "USAA"];  //The third argument, 1, indicates the number of dimensions you are going to include, this does not include the main account.
AxdDimensionUtil::getLedgerAccountId(myContainer);
Here is another example constructing the contents of the
container with the dimensions included in the demo data

    // Construct input
    dimensionValueIn =
    [
        // Display value      
        strFmt('%1-%2-%3-%4', ‘10060’, '10’, ‘2020’, ‘M010’),
         // Main account
        ‘10060’,
         // Segment count
        3,
         // 2nd segment of 1st hierarchy
        ‘Department’, ‘10’,
        // 3rd segment of 1st hierarchy
        ‘Center’, ‘2020’,
         // 4th segment of 1st hierarchy
        ‘Purpose’, ‘M010’
    ];

Comments

  1. hi Dominic, please change the title for this post. It explains how to create a financial dimension combination, and it is not how to
    create a new financial dimension.

    ReplyDelete

Post a Comment