This post is machine-translated. The original post in german language can be found here.
These post applies to following version:
Dynamics AX 2012
Dynamics AX 2012
This post is part of the series »Dynamics AX 2012 - Financial dimensions«
In Dynamics AX 2012, the handling of financial dimensions has changed. Both on the surface and the underlying data model.
In earlier versions you find one field - usually named dimension - of type array. Now you'll find a field derived from RecId called DefaultDimension (or similar).
In this series I want to specifically address these changes and present one or the other piece of code.
|
|
|
|
|
|
The following job will give you an example, of how to change the value of a dimension within the default dimensions of a record (the example-job changes the value of the dimension costcenter of a customer). In this way and manner individual dimension values can be removed also.
static void changeDimensionValue(Args _args) { DimensionAttributeValueSetStorage dimensionAttributeValueSetStorage; DimensionAttribute dimensionAttribute; CustTable custTable = CustTable::find("US-014"); DimensionValue oldDimensionValue; DimensionValue newDimensionValue = "011"; DimensionDefault newDimensionDefault; #define.dimensionName("CostCenter") DimensionValue getDimensonValue(DimensionDefault _dimensionDefault) { DefaultDimensionView defaultDimensionView; select firstonly DisplayValue from defaultDimensionView where defaultDimensionView.Name == #dimensionName && defaultDimensionView.DefaultDimension == _dimensionDefault; return defaultDimensionView.DisplayValue; } // Get current value oldDimensionValue = getDimensonValue(custTable.DefaultDimension); // Build DimensionAttributeValueSetStorage dimensionAttributeValueSetStorage = DimensionAttributeValueSetStorage::find(custTable.DefaultDimension); // Remove old dimension value dimensionAttribute = DimensionAttribute::findByName(#dimensionName); dimensionAttributeValueSetStorage.removeDimensionAttributeValue( DimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute, oldDimensionValue).RecId); // Set new dimension value if(newDimensionValue != "") { dimensionAttribute = DimensionAttribute::findByName(#dimensionName); dimensionAttributeValueSetStorage.addItem( DimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute, newDimensionValue)); } newDimensionDefault = dimensionAttributeValueSetStorage.save(); ttsbegin; custTable.selectForUpdate(true); custTable.DefaultDimension = newDimensionDefault; custTable.update(); ttscommit; }Screenshot before job
Screenshot after job