How to change the value of a financial default dimension

Replace default financial dimension value
Check that financial dimension value exists:
public static DimensionAttributeValue VKValidateFinancialDimensionValue(DimensionAttribute _dimensionAttribute, str _dimensionValue, boolean _noError = false)
{
    DimensionAttributeValue dimensionAttributeValue;

    dimensionAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValueNoError(_dimensionAttribute, _dimensionValue, false, true);

    if (!dimensionAttributeValue && !_noError)
    {
        error(strFmt("@SYS342560", _dimensionValue));
    }

    return dimensionAttributeValue;
}
Get financial dimension value:
public static DimensionValue VKGetFinancialDimensonValue(DimensionDefault _dimensionDefault, Name _dimensionName)
{
    DefaultDimensionView defaultDimensionView;
    
    select firstonly DisplayValue
    from defaultDimensionView
    where defaultDimensionView.Name == _dimensionName
        && defaultDimensionView.DefaultDimension == _dimensionDefault;

    return defaultDimensionView.DisplayValue;
}
Change/replace financial dimension value:
public static DimensionDefault changeFinancialDimensionValue(DimensionDefault _dimensionDefault, Name _dimensionName, DimensionValue _newDimensionValue)
{
    DimensionAttributeValueSetStorage   dimensionAttributeValueSetStorage;
    DimensionAttribute                  dimensionAttribute;
    DimensionValue                      oldDimensionValue;
    DimensionDefault                    newDimensionDefault;

    // Get current value
    oldDimensionValue = BHFFunctions::getFinancialDimensonValue(_dimensionDefault, _dimensionName);

    // Build DimensionAttributeValueSetStorage
    dimensionAttributeValueSetStorage = DimensionAttributeValueSetStorage::find(_dimensionDefault);

    // Remove old dimension value
    dimensionAttribute = DimensionAttribute::findByName(_dimensionName);
    dimensionAttributeValueSetStorage.removeDimensionAttributeValue(
        DimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute, oldDimensionValue).RecId);

    // Set new dimension value
    if(_newDimensionValue)
    {
        dimensionAttributeValueSetStorage.addItem(
            DimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute, _newDimensionValue, false, true));
    }

    newDimensionDefault = dimensionAttributeValueSetStorage.save();

    return newDimensionDefault;
}
Other helper classes, which contain static methods to help with finantial dimensions:
DimensionDefaultingService
AxdDimensionUtil
DimensionDefaultingEngine

Search

About

DaxOnline.org is free platform that allows you to quickly store and reuse snippets, notes, articles related to Dynamics AX.

Authors are allowed to set their own AdSense units.
Join us.

Blog Tags