DEV Community

Eduardo Silva Rossi
Eduardo Silva Rossi

Posted on

How to resolve budget ledger dimension in X++/D365 F&O

Sometimes we get a requirement to create Budget register entries by X++ code and moments later we realize that the usual methods of creating ledger dimensions used for ledger journals doesn't work in this scenario.

This happens because budget and ledger accounts have different sets of ledger dimensions based on defined Budgeting module parameters (Budgeting/Setup/Basic budgeting/Budgeting dimensions). In this case we should resolve our ledger dimension using the code bellow:

public static void main(Args _args)
{
    BudgetAccountContract budgetAccountContract = new BudgetAccountContract();

    budgetAccountContract.parmValues(new List(Types::Class));
    budgetAccountContract.parmAccountStructure('Manufacturing P&L');

    DimensionAttributeValueContract dimensionAttributeValueContract;

    dimensionAttributeValueContract = DimensionAttributeValueContract::construct('MainAccount', '607200');
    budgetAccountContract.parmValues().addEnd(dimensionAttributeValueContract);

    dimensionAttributeValueContract = DimensionAttributeValueContract::construct('BusinessUnit', '002');
    budgetAccountContract.parmValues().addEnd(dimensionAttributeValueContract);

    dimensionAttributeValueContract = DimensionAttributeValueContract::construct('Department', '022');
    budgetAccountContract.parmValues().addEnd(dimensionAttributeValueContract);

    BudgetDimensionCombinationServiceProvider budgetDimensionServiceProvider = BudgetDimensionCombinationServiceProvider::newForBudgetAccountContract(budgetAccountContract);
    DimensionStorageResult dimensionStorageResult = budgetDimensionServiceProvider.resolve();

    if (dimensionStorageResult.parmInvalidValue())
    {
        throw Error('Error while resolving ledger dimension.');
    }

    info(strFmt('Budget LedgerDimension RecId: %1', dimensionStorageResult.parmSavedRecId()));
}
Enter fullscreen mode Exit fullscreen mode

With a ledger dimension display value string the solution is even shorter:

BudgetAccountDimensionResolver budgetAccountDimResolver = BudgetAccountDimensionResolver::newResolver('607200-002-022--', 'Manufacturing P&L');
DimensionDynamicAccount ledgerDimension = budgetAccountDimResolver.resolve();
Enter fullscreen mode Exit fullscreen mode

Top comments (0)