Sunday, March 26, 2017

Building Default dimension from existing Default dimension

//Building Default dimension  from existing Default dimension

//Instead of struct (keyword) - Another way to merge dimension

//Merge Dimension functionality will work only when merging dimension value is empty. But in my case, I need to update if it is exist also.
  
DimensionDefault buildDefaultDimension(dimensionDefault _defaultDimension,Description255 _Custom)
    {
        DefaultDimensionView    dimensionView;
        DimensionAttributeValueSetStorage dimensionAttributeValueSetStorage;
        DimensionAttribute dimensionAttribute;
        DimensionAttributeValue dimensionAttributeValue;
        DimensionDefault dimensionDefault;
        Boolean     check = false;
        boolean     customtrue = false;
        #Define.custom("Custom")
        ;
        dimensionAttributeValueSetStorage = new DimensionAttributeValueSetStorage();
        if(_defaultDimension != 0)
        {
            while select dimensionView
                    where dimensionView.DefaultDimension == _defaultDimension
            {
                check = true;
                dimensionAttribute = DimensionAttribute::find(dimensionView.DimensionAttributeId);
                if(dimensionAttribute && dimensionView.DisplayValue)
                {
                    if(dimensionAttribute.Name != #custom)
                    {
                        dimensionAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute, dimensionView.DisplayValue, false, true);
                        dimensionAttributeValueSetStorage.addItem(dimensionAttributeValue);
                        dimensionDefault = dimensionAttributeValueSetStorage.save();
                    }
                    else
                    {
                        customtrue =true;
                        dimensionAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,_Custom, false, true);
                        dimensionAttributeValueSetStorage.addItem(dimensionAttributeValue);
                        dimensionDefault = dimensionAttributeValueSetStorage.save();
                    }
                }
            }
            if(customtrue == false && _custom)
            {
                dimensionAttribute = DimensionAttribute::findByName(#Custom);
                dimensionAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,_custom, false, true);
                dimensionAttributeValueSetStorage.addItem(dimensionAttributeValue);
                dimensionDefault = dimensionAttributeValueSetStorage.save();
            }
        }
        else
        {
            check = true;
            if(_Custom)
            {
                dimensionAttribute = DimensionAttribute::findByName(#Custom);
                dimensionAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,_Custom, false, true);
                dimensionAttributeValueSetStorage.addItem(dimensionAttributeValue);
                dimensionDefault = dimensionAttributeValueSetStorage.save();
            }
        }
        if(check == true)
        {
            return dimensionDefault;
        }
        else
        {
            return 0;
        }
    }

No comments:

Post a Comment

Copy Markup charges while posting purchase invoice using X++

 Copy Markup charges while posting purchase invoice using X++ Class: Important: Code logic is just for Reference.  New class => Duplicate...