/ Microsoft / Get financial dimension value by name using x++

Get financial dimension value by name using x++

Learn, share and spread knowledge

To get financial dimension value by name using x++ in Microsoft Dynamics 365 for Finance and Operations or in Microsoft Dynamics AX 2012 is always difficult. This is a usual problem comes during the Microsoft Dynamics ERP customization or development. If you are having the same problem, you are at right place.

I am sharing the code for all of you so that you should not waste time in writing up the code again. The code is as follow:

//Author: Moeen Ahmed Sultan
//Tel: +92 321 458 9595
//Email: moeenahmedsultan@hotmail.com


//Below is the function which returns the value of given dimension name e.g. BusinessUnit

//For AX 2012
public str getDimensionDisplayValue(RecId defaultDimension, Name dimName)
{
     DimensionAttributeValueSetStorage dimStorage;
     dimStorage = DimensionAttributeValueSetStorage::find(defaultDimension);
     return dimStorage.getDisplayValueByDimensionAttribute(DimensionAttribute::findByName(dimName).RecId);
}

//OR

//For D365FO
public static str getDimensionDisplayValue(RecId defaultDimension, Name dimName)
{
     DimensionAttributeValueSetStorage dimStorage;
     dimStorage = DimensionAttributeValueSetStorage::find(defaultDimension);
     return dimStorage.getDisplayValueByDimensionAttribute(DimensionAttribute::findByName(dimName).RecId);
}


//DefaultDimension is retrived from PurchTable just to give you an example. You can pass any DefaultDimension value
//'Project' is the name of the financial dimension. You can use 'BusinessUnit', 'Worker' or 'CostCenter' etc.
//call the function as follows:

str dimensionValue;

dimensionValue = this.getDimensionDisplayValue(purchTable.DefaultDimension, 'Project'); //For AX2012

//OR

//ClassName is the class in which the function is written. Make it static in D365FO to call it as follows:
dimensionValue = ClassName::getDimensionDisplayValue(purchTable.DefaultDimension, 'Project'); //For D365FO

The function and the way how to call is mentioned in the comments within the code. Kindly read it carefully.

So, this is how you can get financial dimension value by name using x++ in D365FO and in AX2012.  If this helps you, please Like, Comment and Share to help other people.

If you found any ambiguity or a better solution, please feel free to ask.

Blog: Click here

YouTube: Click here

GitHub: Click here

First, solve the problem. Then, write the code. – John Johnson

2 POST COMMENT

Send Us A Message Here

Your email address will not be published. Required fields are marked *

2 Comments