web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / Dynamics AX Tech Center / Replacing Financial Dimensi...

Replacing Financial Dimension value using X++ code in D365F&O (AX 7)

syed baber Profile Picture syed baber 11,633

Recently, I got a requirement to replace financial dimension value using X++ code based on certain conditions for an Inventory journal record. I was trying to do this using AxdDimensionUtil class by calling method getDimensionAttributeValueSetId and passing container variable containing Dimension attribute and its value. After doing this, I found out that this class has become obsolete and it is no longer supported.

So, I dug into the Dimension classes in D365 and able to fullfill the requirement with following piece of code:

LedgerDefaultDimensionValueSet generateDefaultDimension(str _costCentre)
{
List dimensionValue = new List(Types::Class);

DimensionNameValueListContract dimensionNameValueListContract = new DimensionNameValueListContract();
DimensionStorageResult dimensionStorageResult;
DimensionAttributeValueContract dimensionAttributeValueContract;

//#CostCentre is the macro for the name of CostCentre dimension attribute

dimensionAttributeValueContract = DimensionAttributeValueContract::construct(#CostCentre, _costCentre);
dimensionValue.addEnd(dimensionAttributeValueContract);

dimensionNameValueListContract.parmValues(dimensionValue);

dimensionStorageResult = DimensionNameValueListServiceProvider::newForDimensionNameValueListContract(dimensionNameValueListContract).resolve();

return dimensionStorageResult.parmSavedRecId();
}

inventJournalTrans.DefaultDimension = generateDefaultDimension(“8099”);

In the above method, I have passed cost centre financial dimension value and returning DefaultDimension RecId. Later on, I assigned it to the InventJournalTrans record to update the finacial dimension value with the new cost centre value.

Enjoy DAXing.



This was originally posted here.

Comments

*This post is locked for comments