Sunday, 3 April 2022

Unpack ledger dimension x++ D365

 class FCC_TestDim

{

    /// <summary>

    /// Runs the class with the specified arguments.

    /// </summary>

    /// <param name = "_args">The specified arguments.</param>

    public static void main(Args _args)

    {

 

        // DimensionAttributeValueCombination stores the combinations of dimension values

// Any tables that uses dimension combinations for main account and dimensions

// Has a reference to this table’s recid

DimensionAttributeValueCombination dimAttrValueComb;

        //GeneralJournalAccountEntry is one such tables that refrences DimensionAttributeValueCombination

        GeneralJournalAccountEntry gjAccEntry;

        // Class Dimension storage is used to store and manipulate the values of combination

        DimensionStorage dimensionStorage;

        // Class DimensionStorageSegment will get specfic segments based on hierarchies

        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);

 

        // Get dimension storage

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

        if (dimensionStorage == null)

        {

            throw error("@SYS83964");

        }

 

        // Get hierarchy count

        hierarchyCount = dimensionStorage.hierarchyCount();

        //Loop through hierarchies to get individual segments

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

        {

 

            //Get segment count for hierarchy

            segmentCount = dimensionStorage.segmentCountForHierarchy(hierarchyIndex);

 

            //Loop through segments and display required values

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

            {

                // Get segment

                segment = dimensionStorage.getSegmentForHierarchy(hierarchyIndex, segmentIndex);

 

                // Get the segment information

                if (segment.parmDimensionAttributeValueId() != 0)

                {

                    // Get segment name

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

                    //Get segment value (id of the dimension)

                    segmentValue = segment.parmDisplayValue();

                    segmentDescription = segment.getName();

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

                    {

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

                        //return segmentDescription;

                    }

                }

            }

        }

       // return "";

    }


}

No comments:

Post a Comment