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

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay