Monday, April 12, 2021

Create default dimension using X++ in D365fo

        MapEnumerator           mapEnum;
        boolean                  validDim = true;
        List                    _contractList;
        Map                      dimMap = new Map(Types::String, Types::String);
        RecId                    defaultDimension;
        DimensionDefaultContract dimensionDefaultContract = DimensionDefaultContract::construct();

             
       
        
        dimMap.insert('Client', '003501_036');
        
        dimMap.insert('Purpose', '2016GBG');
        
        dimMap.insert('Division', 'CORP');
        
        dimMap.insert('Department', 'ADMIN');
        
        dimMap.insert('Location', 'LOSANGELES');
        
        dimMap.insert('SubDepartment', 'AP');
        
        dimMap.insert('Employee', '100077');
                   
        mapEnum = dimMap.getEnumerator();

        while(mapEnum.moveNext())
        {
            str     dimName, dimValue;
            boolean dimNameValid;

            dimName      = mapEnum.currentKey();
            dimValue     = mapEnum.currentValue();
            
            
            DimensionAttributeValueContract dimAttrValContract = DimensionAttributeValueContract::construct(dimName, dimValue);
            _contractList = dimensionDefaultContract.parmValues();
            _contractList.addEnd(dimAttrValContract);
          
        }

        if(dimensionDefaultContract && !dimensionDefaultContract.parmValues().empty())
        {
            DimensionNameValueListServiceProvider dimensionDefaultServiceProvider = DimensionNameValueListServiceProvider::newForDimensionNameValueListContract(dimensionDefaultContract);
            DimensionStorageResult                dimensionStorageResult          = dimensionDefaultServiceProvider.resolve();

            switch(dimensionStorageResult.parmStatus())
            {
                case DimensionStorageResultStatus::Valid:
                    defaultDimension = dimensionStorageResult.parmSavedRecId();
                    break;

                default:
                    error(strFmt("Validation Status: %1", dimensionStorageResult.parmStatus()));
                    break;
            }
        }

                        
        info(strFmt("Default Dimension %1",defaultDimension));

No comments:

Post a Comment

Table browser URL in D365FO

Critical Thinking icon icon by Icons8