Dimension Provider Class and Run-time dimension ranges [AX 2012]

While working on a requirement for ledger amounts, I had to find out a way to filter the transactions for a specific dimension value of a specific dimension type; from ledger transactions of a main account.

Now had it been Ax 2009, it was pretty simple where you could provide a range on Dimensions[arrayIndex] field. But in Ax 2012 the dimensions on a transaction are always stored a combination value rather than a separate value.

While running the query, I found a support provided by MS where-in all the dimensions will be added as fields for a table having Ledger dimensions on run-time. Now if we were running a query manually, we will be able to specify the range manually as shown below:

For demo purpose, I am using GeneralJournalAccountEntry table that holds the amounts for transactions posted to a main account

image

Now try and add a range, when you select the drop-down on the Field column, you will notice new fields added to the drop-down

image

The concept behind is that, these fields are added at run-time and when you add a range to any of these fields, a view (DimensionAttributeLevelValueView) will be dynamically added for each field range record you create, as a child DS for GeneralJournalAccountEntry

image 

This is what the SQL statement looks like at the backend

SELECT * FROM GeneralJournalAccountEntry(GeneralJournalAccountEntry_1) JOIN * FROM DimensionAttributeLevelValueView(DimAttCol_GeneralJournalAccountEntry_1_LedgerDimension_5637145354) ON GeneralJournalAccountEntry.LedgerDimension = DimensionAttributeLevelValueView.ValueCombinationRecId AND ((DimensionAttribute = 5637145354)) AND ((DisplayValue = N’000001′))

Now when we are running queries manually, we can specify such kind of a range, what if we have to do the same thing while running a query at a backend or through a code?

Here comes the DimensionProvider class to our rescue. This class will help us add such ranges as required. Look at the sample job below for some guidance.

static void addDimensionRange(Args _args)

{

    Query                   query = new Query();

    QueryRun                queryRun;

    QueryBuildDataSource    qbds;

    DimensionProvider       dimensionProvider = new DimensionProvider();

    GeneralJournalAccountEntry  accEntry;

    DimensionAttribute      dimAttr;

    Name    dimAttrNameEmpl, dimAttrNameCostCenter;

    int i;

    ;

 

    select firstOnly dimAttr where dimAttr.BackingEntityType == tableNum(DimAttributeHcmWorker);

    dimAttrNameEmpl = dimAttr.Name;

   

    select firstOnly dimAttr where dimAttr.BackingEntityType == tableNum(DimAttributeOMCostCenter);

    dimAttrNameCostCenter = dimAttr.Name;

   

    qbds = query.addDataSource(tableNum(GeneralJournalAccountEntry));

 

    dimensionProvider.addAttributeRangeToQuery(query, qbds.name(), fieldStr(GeneralJournalAccountEntry, LedgerDimension), DimensionComponent::DimensionAttribute, SysQuery::valueNotEmptyString(), dimAttrNameEmpl, true);

    dimensionProvider.addAttributeRangeToQuery(query, qbds.name(), fieldStr(GeneralJournalAccountEntry, LedgerDimension), DimensionComponent::DimensionAttribute, SysQuery::valueNotEmptyString(), dimAttrNameCostCenter, true);

 

    queryRun = new QueryRun(query);

    queryRun.prompt();

   

    while(queryRun.next())

    {

        accEntry = queryRun.get(tableNum(GeneralJournalAccountEntry));

        info(strFmt("%1 <–> %2", DimensionAttributeValueCombination::find(accEntry.LedgerDimension).DisplayValue, accEntry.AccountingCurrencyAmount));

    }

}

 

Here is the sample output log

image

This is how the query will be if you prompt the query

image

21 thoughts on “Dimension Provider Class and Run-time dimension ranges [AX 2012]

    1. When I run the above job I am getting below error.

      The Ledger account.SystemGeneratedAttributeEmployee field does not exist.

  1. Hello ,

    I have the same question how to pass dimension ranges values when they were added dynamically .

  2. Hello ,
    When i am trying to replace GeneralJournalAccountEntry table to LedgerJournalTrans table this job is not working …Please can anyone tell why ??

    1. By the way LedgerJournalTrans will not be a straight fit. It depends on Account type. If Account type is ledger, it uses LedgerDimension field otherwise it uses a combination of LedgerDimension and DefaultDimension fields.

  3. Hello ,

    No ouput when i am using LedgerJouralTrans table. debuger is not going in to the While(query.next()) loop . thats why i m not geting any result . Same code is working fine for GeneralJournalAccountEntry table.

  4. If you put this code inside a class which extends RunBaseBatch the dimensions aren’t displayed properly on the Dialog. You get a datasource name of Dimension code set value, and the Dimension label is “Dimension value:”. Is this a bug, or is there a work-around to display the correct financial dimension names?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s