Financial Dimension after save is empty

I have financial dimension which contact values like BuildingID and ContractID. When new building is created, dimension is properly filled with data. But, after that there is need for contract creation. When contract is created there is value in financial dimension field for contractID. But, when contract is saved, financial dimension for contract id disappear. When I check in DIMENSIONATTRIBUTEVALUESET table value for that ContractID dimension is null, there is only value for BuildingID.

Method in dimension helper class which I use for this merging looks like doesn’t do merge. Am I missing something ?

  static server public DimensionDefault tableDimension(Common _c, DimensionDefault _d)
        DimensionAttribute dimensionAttribute;
        DimensionAttributeValue dimensionAttributeValue;
        DimensionAttributeSetItem dimensionAttributeSetItem;
        DimensionAttributeValueSetStorage dimensionAttributeValueSetStorage;
        DimensionDefault cDimensionDefault;
        DimensionDefault ret;
        ret = _d;
        select firstonly RecId from dimensionAttribute
            where dimensionAttribute.BackingEntityTableId == _c.TableId
            join firstonly RecId from dimensionAttributeSetItem
                where dimensionAttributeSetItem.DimensionAttributeSet == DimensionCache::getDimensionAttributeSetForLedger()
                   && dimensionAttributeSetItem.DimensionAttribute == dimensionAttribute.RecId;
        if (dimensionAttributeSetItem.RecId != 0)
            dimensionAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndEntityInst(dimensionAttribute.RecId, _c.RecId, false, true);
            if (dimensionAttributeValue.RecId != 0)
                dimensionAttributeValueSetStorage = new DimensionAttributeValueSetStorage();
                dimensionAttributeValueSetStorage.addItemValues(dimensionAttributeValue.DimensionAttribute, dimensionAttributeValue.RecId, dimensionAttributeValue.HashKey);
                cDimensionDefault =;
                if (cDimensionDefault != 0)
                    ret = LedgerDimensionDefaultFacade::serviceMergeDefaultDimensions(cDimensionDefault, _d);

        return ret;