Monday, April 13, 2015

Hi DAX folks

Hope all DAX consultants are enjoying implementation of powerful, simple and agile ERP MS Dynamics Ax 2012.

This post subjects to get dimension values from LedgerDimensionAccount. This code is very helpful as often we require to get dimension values while dealing with reports in financial modules.

Let's have look at the code :

private void getDimensionDisplay(DimensionDynamicAccount  _dimensionDynamicAccount,
                                          FuturePerExpTable    _futurePerExpTable)

        DimensionStorage                    dimensionStorage;
        DimensionStorageSegment             segment;
        int                                 segmentCount, segmentIndex;
        int                                 hierarchyCount, hierarchyIndex;
        str                                 segmentName, segmentDescription;
        DimensionDisplayValue               segmentValue;
        // Get dimension storage
        dimensionStorage = DimensionStorage::findById(_dimensionDynamicAccount);
        if (dimensionStorage == null)
            throw error("@SYS83964"); //wrong parameters specified.

        // Get hierarchy count
        hierarchyCount = dimensionStorage.hierarchyCount();
        //Loop through hierarchies to get individual segments
        for(hierarchyIndex = 1; hierarchyIndex <= hierarchyCount; hierarchyIndex++)
            setPrefix(strFmt("Hierarchy: %1", DimensionHierarchy::find(dimensionStorage.getHierarchyId(hierarchyIndex)).Name));
            //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();
                    //Get segment value name (Description for dimension)
                    segmentDescription  = segment.getName();

                        if(segmentName == "L1_PGU")
                            _futurePerExpTable.PGU =  segmentValue;
                        if(segmentName == "L7_BusinessLocationCode")
                            _futurePerExpTable.BuisnessLocationCode =  segmentValue;


This code takes ledgerDimensionAccount and the table where dimension are need to be stored for display, as parameters. We then used some of the system classes dedicated for dimension framework and looped through the financial dimension segments.

We could also make use of this code to get values of default dimension by using following method.

DimensionDefaultingService::serviceCreateLedgerDimension(RecId _ledgerDimensionId,
          DimensionDefault _defaultDimension).

This code takes an instance of ledger dimension and default dimension. This method returns the LedgerDimensionAccount to us which we can pass in our getDimensionDisplay() method and get the dimension values.

Hope this post would surely help you. In case of any query you could simply comment over here.

Happy DAXing :) 

No comments:

Post a Comment