Given the AX 2009 statement:
ledgerJournalTrans.Dimension = ledgerTable.Dimension; ledgerJournalTrans.Dimension[1] = "abc";
What is the equivalent way to that in AX 2012?
This will of cause assume the existence of a “Department” dimension as the first dimension.
My case was the “default dimensions” scenario, so I had to adapt a little. This is the method I eventually used:
On the DimensionAttribute table add a new field name Number then add this method:
public static DimensionAttribute findByNumber(DimensionOrdinal _number) { DimensionAttribute dimensionAttribute; select firstonly dimensionAttribute where dimensionAttribute.Number == _number; return dimensionAttribute; }
This explicitly identifies the dimension with a corresponding number.
On the DimensionAttributeValueSetStorage class add the method:
public void addItemNumber(DimensionOrdinal _idx, SysDim _value) { DimensionAttributeValue attrValue; DimensionAttribute attr = DimensionAttribute::findByNumber(_idx); if (!attr) throw error(strFmt("@SYS342559", _idx)); attrValue = DimensionAttributeValue::findByDimensionAttributeAndValue(attr, _value, false, true); this.addItemValues(attr.RecId, attrValue.RecId, attrValue.HashKey); }
The DimensionAttributeValueSetStorage handles “default dimensions” as described in the white paper @dlannoye mentioned.
Then the corresponding code read like this:
dimensionStorage = DimensionAttributeValueSetStorage::find(salesTable.DefaultDimension); dimensionStorage.addItemNumber(1, "abc"); salesTable.DefaultDimension = dimensionStorage.save();