D365 Developer Series: Merging Financial Dimensions in D365 F&O

developer working on laptop computer

How to merge financial dimensions via code in Microsoft Dynamics 365

Merging financial dimensions is a common task that a developer may need to perform via x++ code in Microsoft Dynamics 365. This blog will demonstrate two different approaches for merging financial dimensions. The first example is using a standard business process. The second example is a custom example where we will look at an alternative way to merge default dimensions. Additionally, we will discuss some limitations and expected results when merging financial dimensions in D365.

Example of a Standard Process

A great example that exists in the system is when a sales line is initially created. By default, the line will copy the sales header default dimension. Once an item is specified, the sales line will be updated with a financial dimension that merges the value of the sales line and the item’s default dimension. Below you can see the method on the sales line that performs this operation.

public DimensionDefault mergeDimension(
	DimensionDefault _primaryDefaultDimension,
	DimensionDefault _secondaryDefaultDimension = 0,
	DimensionMerge _dimensionMerge =DimensionMerge::newFromTable(this,
		return _dimensionMerge.merge(_primaryDefaultDimension,_secondaryDefaultDimension);

The method above takes in the two separate DimensionDefault parameters to merge and create a new DimensionMerge object instance with the basis being sales line. In order to instantiate your own DimensionsMerge object, you will need to pass in an instance of the table you are modifying that has a mapping to the DimensionDefaultMap, as well as the recId of the company the financial dimension belongs to. Once you have that object you may simply call the merge method passing in the two DimensionDefault fields to be merged. Note that the DimensionDefault data type is a 64-bit integer that references a DimensionAttributeValueSet record.

Example of a Custom Merge

There is a second way of merging default dimensions that can be used. Using this option can be handy if all you have are the default dimension values which do not utilize the DimensionDefaultMap object. In this example, we still pull our values from table buffers, but they are not required. Below is a snippet of code that demonstrates this.

public void mergeFinDim()

	SalesLine salesLine;
	InventTable inventTable;

	//USMF data
	salesLine = SalesLine::find('001012', 1, true);
	inventTable = InventTable::find('A0001');
	salesLine.DefaultDimension =
					salesLine.DefaultDimension, inventTable.DefaultDimension);

In this method of merging financial dimensions, you do not need any other objects other than at least two DimensionDefault values. You should ensure that the dimension values that are passed into the service method are in priority order.

The merged dimension is initialized from the first supplied default dimension values. Subsequent dimension values are added to the merged dimension if they are blank in the merged dimension. Below is a table demonstrating the inputs and outputs of the custom merge example:

Default DimensionBusiness UnitCost CenterDepartmentItem Group
Sales Line 1001Trade ShowSales 
Item A0001 ProductionHRAudio
Merged Dimension001Trade ShowSalesAudio

If you are using the LedgerDimensionDefaultFacade class in your solution, you will need to reference the Ledger and Dimension packages in your model.

In this blog, we have demonstrated how a developer can merge default dimensions. We demonstrated two separate approaches with examples and discussed key points the developer should be aware of when using these tools.

Deep Expertise in Dynamics AX and D365 Development

enVista is dedicated to helping the Microsoft community by continuously sharing our in-depth knowledge of X++ and Microsoft Dynamics 365 development. If you are struggling with Dynamics AX or D365 development, contact us, and we will connect you with one of our in-house experts.  

Read our other topics in our D365 Developer Series: 

Extending Full-Text within Retail and Commerce

When, Why, and How to Use Data Contracts in Dynamics 365

Using Chain of Command in X++

SysLastValue in a Single Line

About the Author

Related Posts


The Business Case for Dynamics GP to Dynamics 365 F&SC Migration

The transition from Microsoft Dynamics GP to Dynamics 365 Finance & Supply Chain represents more than just a software upgrade—it’s a strategic move toward future-proofing your business. With the right partner and a holistic approach to migration, organizations can embrace the modern capabilities of F&SC.

Read Blog
Shopping Basket

Contact enVista

Thousands of clients across a variety of industries consider enVista an integral and important part of their business strategy. You should, too.
Notification Header
The leading news agency comes to your smartphone.  Download now.