Lookup Financial Dimension in AX 2012

Financial Dimensions have changed in AX 2012. In contrast to earlier versions of Dynamics AX, financial dimensions now are somehow similar to inventory dimensions where a certain combination of dimension values are stored as dimension set. I faced a requirement that an external application (SharePoint based DMS) sends a certain combination of financial dimensions and AX has to assign this combination to a certain record. Here is a (simplified) code how to check the existence of such a dimension.

// Example:
// Business Unit 005 Electronics
// Department 025 IT
// ItemGroup Services

//Step 1: Find Dimension Attributes

DimensionAttribute  attributeBU = DimensionAttribute::findByLocalizedName("BusinessUnit");
DimensionAttribute  attributeDP = DimensionAttribute::findByLocalizedName("Department");
DimensionAttribute  attributeIG = DimensionAttribute::findByLocalizedName("ItemGroup");

//Step 2: Find Dimension Attributes Values

DimensionAttributeValue valueBU = DimensionAttributeValue::findByDimensionAttributeAndValue(attributeBU,"005");
DimensionAttributeValue valueDP = DimensionAttributeValue::findByDimensionAttributeAndValue(attributeDP,"025");
DimensionAttributeValue valueIG = DimensionAttributeValue::findByDimensionAttributeAndValue(attributeIG,"Services");

//Step 3: Create an Array of Hash Keys from the Attribute Values 

DimensionSHA1Hash hashKey;
DimensionAttributeValueSet valueSet;

HashKey dimAttrHashKeyArray[];
dimAttrHashKeyArray[1] = valueBU.HashKey;
dimAttrHashKeyArray[2] = valueDP.HashKey;
dimAttrHashKeyArray[2] = valueIG.HashKey;

hashKey = DimensionAttributeValueSetStorage::getHashFromArray(dimAttrHashKeyArray,3);

//Step 4: Lookup Hash Key

valueSet = DimensionAttributeValueSet::findByHash(hashKey);

if(valueSet.RecId != 0)
    info("Dimension found!");

Über erpcoder
Software Engineer and Dynamics AX enthusiast working in Research & Development for InsideAx

Kommentar verfassen

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:


Du kommentierst mit Deinem WordPress.com-Konto. Abmelden /  Ändern )

Google+ Foto

Du kommentierst mit Deinem Google+-Konto. Abmelden /  Ändern )


Du kommentierst mit Deinem Twitter-Konto. Abmelden /  Ändern )


Du kommentierst mit Deinem Facebook-Konto. Abmelden /  Ändern )

Verbinde mit %s

%d Bloggern gefällt das: