Search This Blog

Friday 1 June 2018

Get Financial Dimension using default dimension through x++ code and Sql in Dynamics AX #D365forOps


Below is the X++ code snippet for getting the Financial Dimensions using Default Dimension by using X++ code:

private str getFinancialDimensionName(Name _dimAttrName, DimensionDefault _defaultDimension)
    {
        DimensionAttribute dimAttr;
        DimensionAttributeValueSetStorage dimStorage;
        DimensionAttributeValue     dimAttrValue;
        Common                      common;
        DictTable                   dictTable;

        select firstOnly dimAttr where dimAttr.Name == _dimAttrName;
        if(dimAttr)
        {
            dimStorage = DimensionAttributeValueSetStorage::find(_defaultDimension);

            select firstonly dimAttrValue
            where dimAttrValue.RecId == dimStorage.getValueByDimensionAttribute(dimAttr.recID)
            join dimAttr
            where dimAttr.RecId == dimAttrValue.DimensionAttribute;

            if (dimAttrValue)
            {
                dictTable = new DictTable(dimAttr.BackingEntityType);
                common = dictTable.makeRecord();

                if (common.TableId)
                {
                    select common where common.(dimAttr.KeyAttribute) == dimAttrValue.EntityInstance;
                    return common.(dimAttr.NameAttribute);
                }
            }
        }

        return "";
}

Where _dimAttrName = name of the dimension attribute like Department, Location etc

and _defaultDimension = value of the defaultDimension like value in DefaultDimension field of table HcmEmployment.

Below is the code snippet to get the department and location in Sql using default dimension.

select dimensionFinancialTag.description from  DefaultDimensionView
join dimensionFinancialTag on dimensionFinancialTag.VALUE = DefaultDimensionView.DISPLAYVALUE
    where DefaultDimensionView.DefaultDimension = 5637144783
      and DefaultDimensionView.Name = 'Location' 


select DisplayValue, dimAttributeOMDepartment.NAME from defaultDimensionView
 join dimAttributeOMDepartment
            on dimAttributeOMDepartment.Value = defaultDimensionView.DisplayValue
        where defaultDimensionView.DefaultDimension = 5637144783

            and defaultDimensionView.name = 'Department'

For Any Question feel free to Comment.

Thanks,
Zahid