Sunday, April 12, 2015

Hi All

Hope All Dynamics Ax consultants are doing good and rocking in implementations of powerful, simple and agile ERP MS Dynamics Ax 2012 :) .

This post by me subjects to populating data from some master in dimension values. You could also use the same logic in creating dimension values in migrations.

The code here was used in a job. Let's have a look


static void createBatchDim(Args _args)
    {
         OMOperatingUnit     operatingUnit;
         DimensionAttributeValueSetStorage   dimstorage;
         InventBatch         inventBatchTable,inventBatchTableDim;
         Name dimName = "L4_CostCenter";
         str 255 dimValue;
         DimensionAttribute   dimattributeContract;
         DimensionAttributeValue       dimAttributeValue;
         recId                           defaultDim;
        ;
        while select inventBatchTable
            where inventBatchTable.inventBatchId!=""
        {
            ttsBegin;
            select  operatingUnit
                where operatingUnit.OMOperatingUnitNumber == inventBatchTable.inventBatchId &&
                      operatingUnit.OMOperatingUnitType   == OMOperatingUnitType::OMCostCenter;
                if(!operatingUnit)
                {
                    operatingUnit.clear();
                    operatingUnit.OMOperatingUnitNumber = inventBatchTable.inventBatchId;
                    operatingUnit.initValue();
                    operatingUnit.OMOperatingUnitType = OMOperatingUnitType::OMCostCenter;
                    operatingUnit.Name = inventBatchTable.inventBatchId;
                    operatingUnit.insert();
 
 
                    dimStorage = DimensionAttributeValueSetStorage::find(InventTable::find(inventBatchTable.itemId).DefaultDimension);
                    dimattributeContract = DimensionAttribute::findByName(dimName);
                    dimValue = inventBatchTable.inventBatchId;
                    if(dimValue)
                    {
                         dimAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimattributeContract, dimValue, true, true);
                         dimStorage.addItem(dimAttributeValue);
                    }
                   else
                        dimStorage.removeDimensionAttribute(DimensionAttribute::findByName(dimName).RecId);
                        defaultDim =  dimStorage.save();
 
            }
                 ttsCommit;
        }
    }

Here I had to populate inventory batch as cost center dimension which is linked to General Ledger>Setup>Organization>Cost centers

So i just picked up the inventory batch which didn't exist in cost center master and made the available in dimension values of Cost center dimension.

Hope this post would surely help you. In case of any query you could simply comment over here.

Happy DAXing :) 

No comments:

Post a Comment