Thursday, 24 March 2022

To get Name, Value, Description of Dimension in D365 F&O

 class TST_DimValues

{

    public static void main(Args _args)

    {       

DimensionAttributeValueCombination dimAttrValueComb;

        GeneralJournalAccountEntry gjAccEntry;

        DimensionStorage dimensionStorage;

        DimensionStorageSegment segment;

        int segmentCount, segmentIndex;

        int hierarchyCount, hierarchyIndex;

        str segmentName, segmentDescription,segmentValue;

        LedgerJournalTrans ledgerJournalTrans;

        

        select ledgerJournalTrans where ledgerJournalTrans.JournalNum == "00457";


        dimAttrValueComb = DimensionAttributeValueCombination::find(ledgerJournalTrans.OffsetLedgerDimension);

        dimensionStorage = DimensionStorage::findById(ledgerJournalTrans.OffsetLedgerDimension);

        if (dimensionStorage == null)

        {

            throw error("@SYS83964");

        }

        hierarchyCount = dimensionStorage.hierarchyCount();

        for(hierarchyIndex = 1; hierarchyIndex <= hierarchyCount; hierarchyIndex++)

        {

            segmentCount = dimensionStorage.segmentCountForHierarchy(hierarchyIndex);

            for (segmentIndex = 1; segmentIndex <= segmentCount; segmentIndex++)

            {

                segment = dimensionStorage.getSegmentForHierarchy(hierarchyIndex, segmentIndex);

                if (segment.parmDimensionAttributeValueId() != 0)

                {

                    segmentName = DimensionAttribute::find(DimensionAttributeValue::find(segment.parmDimensionAttributeValueId()).DimensionAttribute).Name;

                    segmentValue = segment.parmDisplayValue();

                    segmentDescription = segment.getName();

                    if(segmentName =="BusinessUnit")//Give the Dimension Name to that Dimension Value

                    {

                        info(strFmt("%1---%2",segmentValue,segmentDescription));

}

                }

            }

        }

    }


}