Monday, 30 July 2018

How to get Financial Dimension value from Worker Position in AX / D365FO / AX 7

Here is the sample X++ code to find financial dimension value from the worker's primary position.

public Name getDimensionValue(HcmWorkerRecId _workerRecId, Name _DimensionName)
{
        HcmPositionDefaultDimension             hcmPositionDefaultDimension;
        DefaultDimensionView                    dimensionView;
        DimensionAttributeValueSet              DimensionAttributeValueSet;
        DimensionAttributeValueSetItem          DimensionAttributeValueSetItem;
        DimensionAttributeValue                 DimensionAttributeValue;
        DimensionAttribute                      DimensionAttribute;
       
        select HcmPositionDefaultDimension where
            HcmPositionDefaultDimension.Position == HcmWorker::getPrimaryPosition(_workerRecId);

        select RecId from DimensionAttributeValueSet
           where  DimensionAttributeValueSet.RecId == HcmPositionDefaultDimension.DefaultDimension
           join RecId, DisplayValue, DimensionAttributeValueSet from DimensionAttributeValueSetItem
           where DimensionAttributeValueSetItem.DimensionAttributeValueSet == DimensionAttributeValueSet.RecId
           join RecId from DimensionAttributeValue
           where DimensionAttributeValue.RecId == DimensionAttributeValueSetItem.DimensionAttributeValue
           join RecId, Name, ValueAttribute from DimensionAttribute
           where DimensionAttribute.RecId == DimensionAttributeValue.DimensionAttribute
                && DimensionAttribute.Name == _DimensionName;

        select dimensionView
            where dimensionView.DefaultDimension == HcmPositionDefaultDimension.DefaultDimension
                && dimensionView.Name == _DimensionName
                && dimensionView.DisplayValue == DimensionAttributeValueSetItem.DisplayValue
                && dimensionView.DimensionAttributeId == DimensionAttribute.RecId;

        return dimensionView.dimensionDiscription();
       
}

No comments:

Post a Comment

Difference Between Edit And Display Method in Ax

Display Method: The display method means that the method’s return value is being displayed on a form or a report.  This value is fixed and c...