Working with financial dimensions LedgerDimension/DefaultDimension

Creating new financial dimension set:
    void VKAddFinancialDimension(DimensionAttributeValueSetStorage _dimSetStorage, str _name, str _value)
    {
        DimensionAttribute      dimAttr = DimensionAttribute::findByName(_name);
        DimensionAttributeValue dimAttrValue;

        dimAttrValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimAttr, _value, false, true);

        if (_dimSetStorage)
        {
            _dimSetStorage.addItem(dimAttrValue);
        }
        else
        {
            throw error(strFmt("Value %1 for dimension %2 not found", _value, _name));
        }
    }
Usage:
        DimensionAttributeValueSetStorage   dimSetStorage = new DimensionAttributeValueSetStorage();
        DimensionDefault                    defaultDimension;

        VKAddFinancialDimension(dimSetStorage, 'FinDimName1', 'FinDimValue');
        VKAddFinancialDimension(dimSetStorage, 'FinDimName2', 'FinDimValue');
        defaultDimension = dimSetStorage.save();
Changing existing financial dimension set:
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;
}
public static DimensionDefault VKChangeFinancialDimensionValue(DimensionDefault _dimensionDefault, Name _dimensionName, DimensionValue _newDimensionValue)
{
    DimensionAttributeValueSetStorage   dimensionAttributeValueSetStorage;
    DimensionAttribute                  dimensionAttribute;
    DimensionValue                      oldDimensionValue;
    DimensionDefault                    newDimensionDefault;
 
    // Get current value
    oldDimensionValue = VKFunctions::VKGetFinancialDimensonValue(_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;
}
Usage:
DimensionDefault newDimensionDefault = ledgerJournalTrans.DefaultDimension;
newDimensionDefault = VKChangeFinancialDimensionValue(newDimensionDefault, 'FinsDimName1', 'FinDimValue');
newDimensionDefault = VKChangeFinancialDimensionValue(newDimensionDefault, 'FinsDimName2', 'FinDimValue');
Applying accounts to ledger dimension.
If ledger (main) account (LedgerJournalACType::Ledger):
MainAccount mainAccount = MainAccount::findByMainAccountId(_lineStaging.MainAccount);
ledgerJournalTrans.AccountType     = LedgerJournalACType::Ledger;
ledgerJournalTrans.LedgerDimension = LedgerDefaultAccountHelper::getDefaultAccountFromMainAccountRecId(mainAccount.RecId);
ledgerJournalTrans.LedgerDimension = LedgerDimensionFacade::serviceCreateLedgerDimension(ledgerJournalTrans.LedgerDimension, defaultDimension);
Other types:
ledgerJournalTrans.AccountType      = LedgerJournalACType::Vend;
ledgerJournalTrans.LedgerDimension  = LedgerDynamicAccountHelper::getDynamicAccountFromAccountNumber('VendAccountNum', ledgerJournalTrans.AccountType);
ledgerJournalTrans.DefaultDimension = defaultDimension;



 

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