Let's walk through creating a standard Build VM
You are here
Merging Default Dimensions in 2012 and D365
Working with finance dimensions in AX / D365 can be difficult sometimes so I thought I would dedicate a few posts to this subject. First, let's cover using class DimensionMerge. Let's consider the code below:
static void Job3(Args _args)
{
SalesLine SalesLine = SalesLine::find("SO00876013",1,true);
InventTable InventTable = InventTable::find("10000001");
ttsBegin;
SalesLine.DefaultDimension = DimensionMerge::newFromTable(SalesLine, SalesLine.companyInfo().RecId).merge(SalesLine.DefaultDimension, InventTable.DefaultDimension);
SalesLine.update();
ttsCommit;
}
AX 2012
This code is getting a sales order line and an item; nothing spectacular. However, next we are calling DimensionMerge::NewFromTable. In 2012, this will take the financial dimension from InventTable and apply them to SalesLine where the SalesLine dimension attribute for each dimension is empty. Let's look at a real example. Consider the following Item:
And also the following Sales Order Line:
When we merge those two default dimension, using the code above, we end up with this on the Sales Order Line:
However, if there is already a value for an attribute, it will not alter the value. Let's modify the Sales Order Line financial dimension to non-standard values:
Next, lets run the code above. Nothing will actually change. The two financial dimension attributes that are different in this instance are ProdLine and Region. However, since the target (salesLine) already has a value for each, the values from the source (InventTable) won't be applied. Another way to do this same thing using DimensionDefaultingService is as follows:
static void Job4(Args _args)
{
SalesLine SalesLine = SalesLine::find("SO00876013",1,true);
InventTable InventTable = InventTable::find("10000001");
ttsBegin;
SalesLine.DefaultDimension = DimensionDefaultingService::serviceMergeDefaultDimensions(SalesLine.DefaultDimension, InventTable.DefaultDimension);
SalesLine.update();
ttsCommit;
}
D365FOEE
In D365, the same principles apply and the DimensionMerge class is still there. Lots of other things have changed but this is still a valid way to manipulate dimesions between the two versions assuming this is the behavior you want. From a quick review, the other ways to alter financial dimensions have changed so there are a few new things to learn. The equivilent code in D365 is simple. If you are using DimensionMerge, there is no change. If you are using DimensionDefaultingService, It's a one line change:
SalesLine.DefaultDimension = ledgerDimensionDefaultFacade::serviceMergeDefaultDimensions(SalesLine.DefaultDimension, InventTable.DefaultDimension);
DimensionDefaultingService is gone but we now have LedgerDimensionDefaultFacade to do very similar things as well as another class called LedgerDimensionFacade to do related things. More info on that can be found here.