0

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. I have this method for init dimensions:

void initDimensions()
    {        
        DimensionDefault dimension;
        PMGOrgDimension orgDimension;
        CompanyId       companyId;        
        PMEGround ground;
        PMEBuilding building;

        switch(pmcContract.EstateType)
        {            
            case PMCEstateType::Ground :
                ground = PMEGround::find(pmcContract.EstateId);
                dimension    = PMEObjectLegalEntity::find(ground.TableId, ground.RecId).DefaultDimension;
                orgDimension = ground.OrgDimension;
                companyId    = ground.CompanyId;
                break;
            case PMCEstateType::Building :
                building = PMEBuilding::find(pmcContract.EstateId);
                dimension    = PMEObjectLegalEntity::find(building.TableId, building.RecId).DefaultDimension;
                orgDimension = building.OrgDimension;
                companyId    = building.CompanyId;
                break;
            default :
                dimension = pmcContract.DefaultDimension;
                orgDimension = pmcContract.OrgDimension;
                companyId = pmcContract.CompanyId;
                break;
        }

        pmcContract.DefaultDimension    = dimension;
        pmcContract.OrgDimension = orgDimension;
        pmcContract.CompanyId    = companyId;

    } 

Is there something what I missing ?

DarthCSharper
  • 133
  • 1
  • 13

2 Answers2

2

Try changing this line:

pmcContract.DefaultDimension = dimension;

To this:

pmcContract.DefaultDimension = DimensionDefaultingService::serviceMergeDefaultDimensions(pmcContract.DefaultDimension, dimension);

Alex Kwitny
  • 11,211
  • 2
  • 49
  • 71
  • I tried. Doesn't work, in D365, there is no DimensionDefaultingService, I used LedgerDimensionDefaultFacade. But thank you a lot. It looks like it's not regarding initDimension method, instead, it's where it's called. – DarthCSharper Jun 21 '19 at 15:32
  • Regarding dimensions in general, if a dimension is already set, it gets a `RecId` stored in `DefaultDimension` and if you want to set another dimension, you would need to merge them. Similar to having an `InventDimId` set where you only have `Site`...if you want to specify a warehouse, you would need to `findOrCreate` or effectively merge the site/warehouse to get a new `InventDimId`. Hope this makes sense. I was thinking you needed to check if `pmcContract.DefaultDimension` already had a value stored. – Alex Kwitny Jun 21 '19 at 16:58
  • Issue probably is not in the declaration of method. It's in the place where is called. There is code behind entire form. https://github.com/DarkhVader/AXDev/blob/master/PMCContractDetails.xpp – DarthCSharper Jun 24 '19 at 09:51
  • Also, helper class, which can handle only one value per call... https://github.com/DarkhVader/AXDev/blob/master/PMGDimensionCl – DarthCSharper Jun 24 '19 at 12:17
0

Issue is in this method:

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 = dimensionAttributeValueSetStorage.save();
                if (cDimensionDefault != 0)
                {
                    ret = LedgerDimensionDefaultFacade::serviceMergeDefaultDimensions(cDimensionDefault, _d);
                }
            }
        }

        return ret;
    }

Merge is not working. It only takes values for _d. Not merging them.

DarthCSharper
  • 133
  • 1
  • 13