top of page
Suche
AutorenbildPedro Rodriguez

Calculate Ledger balance with dimensions with X++



Recently, as I had to migrate some Dynamics Ax 2009 code, I found me with the task to calculate the Ledger balance with Dimensions. Same results yould get with the Trial balance report. Here the code that could save you some hours.


The parameter _dimensions is a Map with the pairs dimension name/value including the ledger account.

The parameter _dimensionSetName is the name of the Dimension Set. You may need to set up the right dimension sets for your examples.


public AmountMST calculateBalance(Map _dimensions,str _dimensionSetName, TransDate _fromDate, TransDate _toDate)

{

AmountMST balanceAmount;

List dimensionValuesList;

DimensionSetContract dimensionSet = new DimensionSetContract();

DimensionAttributeValueContract dimensionAttributeValueContract;

RecId ledgerDimensionId;

RecId ledgerId;

DimensionAttributeValueCombination dimAttrValueCombo;

LedgerBalanceDimAttrValueComboAmounts ledgerBalance;

DimensionServiceProvider serviceProvider = new DimensionServiceProvider();

DimensionSetBalanceContract result = new DimensionSetBalanceContract();

DimensionSetCombinationContract dimensionSetCombinationContract;

MapEnumerator mapEnumerator;

List postingLayerList = new List(Types::Integer);

dimensionValuesList = new List(Types::Class);



mapEnumerator = _dimensions.getEnumerator();

while (mapEnumerator.moveNext())

{

//The Map _dimensions contains pairs (DimensionName, Value) including the MainAccount

dimensionAttributeValueContract = new DimensionAttributeValueContract();

dimensionAttributeValueContract.parmName( mapEnumerator.currentKey());

dimensionAttributeValueContract.parmValue( mapEnumerator.currentValue());

dimensionValuesList.addEnd(dimensionAttributeValueContract);

}


dimensionSetCombinationContract = new DimensionSetCombinationContract();

dimensionSetCombinationContract.parmValues(dimensionValuesList);

dimensionSetCombinationContract.parmDimensionSetName(_dimensionSetName);


dimensionSet.parmAccountingDateFrom(_fromDate);

dimensionSet.parmAccountingDateTo(_toDate);

dimensionSet.parmCombination(dimensionSetCombinationContract);


dimensionSet.parmIncludeOpeningFiscalPeriod(true);

dimensionSet.parmIncludeClosingFiscalPeriod(false);

dimensionSet.parmIncludeOperatingFiscalPeriod(true);

dimensionSet.parmLedgerName( Ledger::find(Ledger::current()).Name);


// Validate DimensionSetContract

DimensionServiceProvider::validateDimensionSet(dimensionSet);


postingLayerList.addEnd( OperationsTax::Current);

dimensionSet.parmPostingLayerList(postingLayerList);

result = serviceProvider.getBalance( dimensionSet);

balanceAmount = result.parmAccountingCurrencyAmount();

return balanceAmount;

}


2.537 Ansichten0 Kommentare

Aktuelle Beiträge

Alle ansehen

Comments


bottom of page