Thursday, December 21

AX 2012 - Get default financial dimension values through X++ code

There are many areas in AX where "Default Financial Dimension" is used.In many cases we have to show the default financial dimension and its values in either forms or reports,so the key thing is that how do we get the default financial dimension and its value associated to a particular entity though X++ code.Here is the code snippet that will meet your needs.




    DimensionAttributeValueSetStorage    dimStorage;
    HcmPositionDefaultDimension          HcmPositionDefaultDimension;
    DimensionAttribute  DimensionAttribute;
    Counter                                               i;
    DimensionAttribute          dimAttr;
    DimensionAttributeValue     dimAttrValue;
    Common                      common;
    DictTable                   dictTable;
    str                         Name;
    str                         value;

    HcmPositionDefaultDimension = HcmPositionDefaultDimension::findByPositionLegalEntity(5637144830,CompanyInfo::find().RecId);

    dimStorage = DimensionAttributeValueSetStorage::find(HcmPositionDefaultDimension.DefaultDimension);

    for (i=1 ; i<= dimStorage.elements() ; i++)
    {
        select firstonly dimAttrValue
        where dimAttrValue.RecId == dimStorage.getValueByIndex(i)
        join dimAttr
            where dimAttr.RecId == dimAttrValue.DimensionAttribute;

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

            if (common.TableId)
            {
                select common where common.(dimAttr.KeyAttribute) == dimAttrValue.EntityInstance;
                name = common.(dimAttr.NameAttribute);
                value = common.(dimAttr.ValueAttribute);
            }
        }
        info(dimAttr.Name +"----" +value + "----"+name);
    }

No comments:

Post a Comment

Popular Posts