Ledger Dimension Facade Class

 Ledger Dimension Facade Class


When you create a general journal/Payment journal or any journal in D365FO using code (X++) and you face the error below:

Error: Function DimensionValidationRequest::newForLedgerDimensionType has been incorrectly called inD365 F&O

This blog post will help you with the resolution.

I have seen a couple of people face this problem on forums, and the resolution or solution given to them appears to be too bulky or cumbersome. There's actually a better solution by Microsoft, which I'm not sure many are aware of.  Dynamics 365FO has a simpler solution for this, and Microsoft has written an out-of-the-box helper or utility class to solve this.

See the solution in the appendix section at the bottom of the blog, but I urge you to read the blog in its entirety because it has a lot of rich information, especially for developers and solution architects.

It's surprising to know that even ChatGPT isn't aware that this utility class exists in Dynamics. Here's is my conversation with ChatGPT.







The Ledger Dimension Facade class is a helper class in Dynamics that simplifies the manipulation and working with ledger dimensions programmatically (in X++).

What are Ledger Dimensions?

In Dynamics 365 Finance and Operations (D365FO), a ledger dimension is a combination of the main account and additional financial dimensions used to classify and analyse financial transactions.

Key Concepts:

  • Main Account: The core account from the chart of accounts (e.g., 600100 - Travel Expense).

  • Financial Dimensions: Custom attributes that provide additional detail (e.g., Department, Cost Centre, Project).

Together, these form a ledger dimension that determines how transactions are recorded and analysed in the general ledger.

Example

Main Account Department Cost Center Project
600100 022 1001 PROJ123

 This combination becomes a ledger dimension, which is stored as a single value in the system (an ID) that points to this combination of values.

There are several useful key methods of the class, but I would like to focus on the few ones that would come in handy in your day-to-day development.

1. Get Default Dimension From Ledger Dimension:

Use this method to get the default dimension from a ledger dimension. 

Parameter(s) required: LedgerDimension.

Return value: Dimension Default.

LedgerDimensionFacade::getDefaultDimensionFromLedgerDimension(LedgerDimensionBase _ledgerDimensionBase).

2. Get Display Value For Ledger Dimension:

Use this method to get the display value from a ledger dimension.

Parameter(s) required: DefaultDimension

Return value: Dimension Display value.

LedgerDimensionFacade::getDisplayValueForLedgerDimension(DimensionCombinationBase _dimensionCombinationBase);

3. Get Main Account From LedgerDimension:

Use this method to get the main account from a ledger dimension.

Parameter(s) required: LedgerDimension

Return value: Main account (Record).

LedgerDimensionFacade::getMainAccountFromLedgerDimension(LedgerDimensionBase _ledgerDimensionBase);

4. Get Main Account ID from LedgerDimension:

Use this method to get the main account from a ledger dimension.

Parameter(s) required: LedgerDimension

Return value: Main account Num (Id).

LedgerDimensionFacade::getMainAccountIdFromLedgerDimension(LedgerDimensionBase _ledgerDimensionBase);

5. Get Main Account RecID from LedgerDimension:

Use this method to get the main account recid from a ledger dimension.

Parameter(s) required: LedgerDimension

Return value: Main account  (RecId).

LedgerDimensionFacade::getMainAccountRecIdFromLedgerDimension(LedgerDimensionBase _ledgerDimensionBase);

6. Create an instance of a ledger dimension with or without specified Dimensions.

This is my favourite and most used. 

You can use this to create an instance of the ledger dimension with or without specified dimensions. The dimensions value is optional; if you don't want to pass in any dimensions, but you still want to respect the Dimension hierarchy.

Parameter(s) required: LedgerDimension and default dimensions (optional).

Return value: Ledger Dimension Account with the specified dimensions.

LedgerDimensionFacade::serviceCreateLedgerDimension(RecId _ledgerDimension,[DimensionDefault _dimensionDefault1], [DimensionDefault _dimensionDefault2], [DimensionDefault _dimensionDefault3]);

7. Create an instance of a ledger dimension based on a ledger dimension type (with or without specified Dimensions).

Use this to create an instance of a ledger dimension type. 

The types include: Account, Budget, Budget Control, Budget Planning, and Default Account.

Parameter(s) required: LedgerDimension, Ledger Dimension Type, and default dimensions (optional).

Return value: Ledger Dimension Account with the specified combination and ledger dimension type.

LedgerDimensionFacade::serviceCreateLedgerDimensionForType(LedgerDimensionType  _ledgerDimensionType, RecId _ledgerDimension, [DimensionDefault _dimensionDefault1], [DimensionDefault _dimensionDefault2], [DimensionDefault _dimensionDefault3]);

8. Merge Ledger dimensions into one.

Use this to merge ledger dimensions into one. You can either merge ledger dimensions with different dimension combinations into one.

Parameter(s) required: LedgerDimension 1,LedgerDimension 2, Ledger Dimension Type (optional);

Return value: Merged Ledger Dimension Account.

LedgerDimensionFacade::serviceMergeLedgerDimensions(LedgerDimensionBase _ledgerDimension1,LedgerDimensionBase _ledgerDimension2,[LedgerDimensionType _ledgerDimensionType]).


These are the key ones I want to highlight. There are several other methods you can find useful and handy. The beauty of the Ledger Dimension Facade class is that it does a lot of heavy lifting for you.


Appendix 

To solve the error, use method 6 in my blog post:

Create an instance of a ledger dimension with or without specified Dimensions.

Assuming you a table called LedgerTable and you want to the LedgerDimension field on the LedgerJournalTrans. You can do something like this.

LedgerJournalTrans trans; LedgerTable myCustomLedgerTable;

//Just a code snippet

//Do something like this

trans.ledgerDimension = LedgerDimensionFacade::serviceCreateLedgerDimension(myCustomLedgerTable.LedgerDimenion, myCustomLedgerTable.DimensionDefault);


Comments

Popular posts from this blog

Integration Capabilities and Support in Microsoft Dynamics 365 Finance & Operations (F&O) - An Overview

Performance and Monitoring in dynamics 365 F&O.