Showing posts with label Ledger Dimension d365. Show all posts
Showing posts with label Ledger Dimension d365. Show all posts

Wednesday 9 February 2022

Populate LedgerDimension value through code Ax 2012 & D365

Populate LedgerDimension value through code Ax 2012 & D365


public DimensionDynamicAccount getLedgerDimensionId(container _dimensionValue)
    {
        DimensionStorage        dimensionStorage = DimensionStorage::construct(0,      LedgerDimensionType::Account);
        DimensionAttributeValue dimAttributeValue;
        DimensionStorageSegment dimensionStorageSegment;
        DimensionHierarchyLevel dimHierarchyLevel;
        MainAccount             mainAccount;
        Recid                   dimHierarchyId;
        Recid                   mainAccountRecId;
        DimensionValue          dimensionValue;
        container               dimensions;

        for(int i = 1; i<= conLen(_dimensionValue); i++)
        {
            try
            {              
                    // Rest of dimensions
                    if(dimensionValue)
                    {
                        dimAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValueNoError(DimensionAttribute::findByName(conPeek(dimensions, i)), dimensionValue, false, true);
                        if (!dimAttributeValue)
                        {
                            // @JAT:DimensionNotFound = The value '%1' of the dimension '%2' does not exist.
                            throw error(strFmt("DimensionNotFound", dimensionValue, conPeek(dimensions, i)));
                        }
                        dimensionStorageSegment = DimensionStorageSegment::constructFromValue(dimAttributeValue.CachedDisplayValue, dimAttributeValue);
                        dimensionStorage.setSegment(i, dimensionStorageSegment);
                    }
                    else
                    {
                        dimensionStorageSegment = DimensionStorageSegment::emptySegment();
                        dimensionStorage.setSegment(i, dimensionStorageSegment);
                    }
                }
            
            catch
            {
                return 0;
            }
        }
        return dimensionStorage.save();
    }

Saturday 2 January 2021

Create Ledger Dimension through Code (x++)

          Create Ledger Dimension through Code (x++)


Microsoft has provided a service class which has a method provided  internally that merges the default dimension and the ledger account that you require.
This works only when you have default dimension & ledgerAccount that you want to merge .


LedgerDimension = DimensionDerivationDistributionRule::buildLedgerDimension(ledgerDimension,DefaultDimension);


Here the parameter Default dimension is the recid contains combination of your dimension values.
LedgerDimension is the LedgerMainAccount that is defaulted when you creating journals.


P.S : Default dimension creation code is provided in my another blog which return the RecId needed as aa parameter 'DefaultDimension' for the method buildLedgerDimension() in the above one liner code.

Blog for default dimension creation code : 

https://sbdynaax.blogspot.com/2021/01/c-reate-default-dimension-with-set-of.html

Thanks & Regards

Sindhu