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!");
}

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

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

%d bloggers like this: