Purpose:
Demonstrate how can we get dimension display value in X++. This could be pretty handy when we need to display dimension display value on a custom form or an SSRS report for example.
Application:
Dynamics 365 for Finance and Operations
Solution:
You can use the following code to get the dimension display value by passing in default dimension RecId and dimension name string.
Code
/// <summary>
/// Gets dimension display value. Feb 16, 24 MK
/// </summary>
/// <remarks>
/// Gets dimension display value by default dimension and dimension name.
/// </remarks>
public static DimensionValue getDimensionDisplayValue(RecId _defaultDimension, Name _dimName)
{
DimensionAttributeValueSetStorage dimStorage;
dimStorage = DimensionAttributeValueSetStorage::find(_defaultDimension);
return dimStorage.getDisplayValueByDimensionAttribute(DimensionAttribute::findByName(_dimName).RecId);
}
Usage
For example, if you need to get cost center dimension value from a Purchase Order header, then you can get it by passing in the default dimension RecId of PurchTable and cost center dimension string.
#define.CostCenter("CostCenter")
dimCostCenter = MAK_LedgerDimensionHelper::getDimensionDisplayValue(purchTable.DefaultDimension, #CostCenter);