Friday, 3 April 2015

Default dimension storage in Ax 2012 : to fetch one dimension from defauly dimension group

 Hi,

In this post we will see, how to get one dimension value from default dimension master RecId.
Method:

DimensionValue getDimensionValue(RefRecID dimensionSetRecID, Name attributeName)
{
    DimensionAttributeValueSet      dimAttrValueSet;
    DimensionAttributeValueSetItem  dimAttrValueSetItem;
    DimensionAttributeValue         dimAttrValue;
    DimensionAttribute              dimAttribute; 

    dimAttrValueSet = DimensionAttributeValueSet::find(dimensionSetRecID); 

    select dimAttrValueSetItem
        where dimAttrValueSetItem.DimensionAttributeValueSet == dimAttrValueSet.RecId
    join dimAttrValue
        where dimAttrValue.RecId == dimAttrValueSetItem.DimensionAttributeValue
    join dimAttribute
        where dimAttribute.RecId == dimAttrValue.DimensionAttribute
        &&    dimAttribute.Name  == attributeName; 

    return dimAttrValue.getValue();
}
 
e.g.: Our task is to get "Importer"only through default dimension (here Importer is CustAccount) then we need to call this method like that:
 
importerDimension = CustTable::find(this.getDimensionValue(SalesTable.DefaultDimension, "Importer"));
    if (importerDimension)
    {
        msCommercialPackingSlipTmp.msImporterName = CustTable::find(importerDimension).name();
        msCommercialPackingSlipTmp.msImporterAddress = CustTable::find(importerDimension).address();
    }
    else
    {
        msCommercialPackingSlipTmp.msImporterName = msCommercialPackingSlipTmp.DeliveryName;
        msCommercialPackingSlipTmp.msImporterAddress = msCommercialPackingSlipTmp.DeliveryAddress;
    }
 
Happy DAXing....
 

No comments:

Post a Comment