web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :

Get default financial dimension values through X++ code

Muhammad Yasir Profile Picture Muhammad Yasir 1,023
Hi,

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.

I am using Project table with which Financial Dimensions have been attached already.

Code Example 1

ProjTable                                       ProjTable;
DimensionAttributeValueSet           DimensionAttributeValueSet;
DimensionAttributeValueSetItem    DimensionAttributeValueSetItem;
DimensionAttributeValue                DimensionAttributeValue;
DimensionAttribute                         DimensionAttribute;

while select * from ProjTable
        where ProjTable.ProjId == "10005"    //  To display value for ProjectId "10005" only
join RecId from DimensionAttributeValueSet
        where  DimensionAttributeValueSet.RecId == ProjTable.DefaultDimension
join RecId, DisplayValue from DimensionAttributeValueSetItem
        where DimensionAttributeValueSetItem.DimensionAttributeValueSet == DimensionAttributeValueSet.RecId
join RecId from DimensionAttributeValue
        where DimensionAttributeValue.RecId == DimensionAttributeValueSetItem.DimensionAttributeValue
join RecId, Name from DimensionAttribute
        where DimensionAttribute.RecId == DimensionAttributeValue.DimensionAttribute
    {
        info(DimensionAttribute.Name+"----"+ DimensionAttributeValueSetItem.DisplayValue);
    }


Code Example 2
The same result can also be achieved using "DimensionAttributeValueSetStorage" class.

DimensionAttributeValueSetStorage    dimStorage;
ProjTable                                            ProjTable;
Counter                                               i;

ProjTable = ProjTable::find("10005");    //  To display value for ProjectId "10005" only
dimStorage = DimensionAttributeValueSetStorage::find(ProjTable.DefaultDimension);

for (i=1 ; i<= dimStorage.elements() ; i++)
{
info(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name +"----" +dimStorage.getDisplayValueByIndex(i));
}

Here is the result for the above piece of codes.



Code Example 3
The same result can also be achieved using "AxdDimensionUtil" class.

ProjTable   ProjTable;
Counter     i;
container   conDim;

ProjTable = ProjTable::find("10005");     //  To display value for ProjectId "10005" only
conDim = AxdDimensionUtil::getDimensionAttributeValueSetValue(ProjTable.DefaultDimension);

for (i=1 ; i<= conLen(conDim) ; i++)
{
     info(conPeek(conDim,i));
}

By using this code we get a slightly different result.The first line shows the no of dimensions associated with the entity while the rest of the lines show the dimension name and their respective values associated with the entity(Project).


Happy coding :)



This was originally posted here.

Comments

*This post is locked for comments