Update Dimensions for the Item,Customer and Vendor

Some times you may get a strange requirement from client to update few dimensions on Default Dimensions :

Below code snippet is used to update the required dimensions without disturbing the other dimensions


//Bellow example will remove the BU,Dept and CC without distrubing the other dimensions
static void ItemDimUpdate(Args _args)
{
    InventTable inventTable,inventTableselect;
    container dimValue;
    DimensionDefault DimensionDefault,DimensionDefault1;
    str BussinessUnit,CostCenter,Department,ItemGroup,Project;
    int i = 0;

    DimensionAttributeValueSetStorage       dimStorage;
    CustTable                               custTable;
    Counter                                 c;
    

    ttsBegin;
    while select * from inventTableselect
    {
         i = 0;
         BussinessUnit = "";
         CostCenter = "";
         Department = "";
         ItemGroup = "";
         Project = "";
         dim = new Struct();
         dimValue = connull();

        //Getting values from the Old Dimension
        dimStorage = DimensionAttributeValueSetStorage::find(inventTableselect.DefaultDimension);
        for (c=1 ; c<= dimStorage.elements() ; c++)
        {
            switch (DimensionAttribute::find(dimStorage.getAttributeByIndex(c)).Name)
            {
                case 'BussinessUnit':
                    BussinessUnit = dimStorage.getDisplayValueByIndex(c);
                break;
                case 'CostCenter':
                    CostCenter = dimStorage.getDisplayValueByIndex(c);
                break;
                case 'Department':
                    Department = dimStorage.getDisplayValueByIndex(c);
                break;
                case 'ItemGroup':
                    ItemGroup = dimStorage.getDisplayValueByIndex(c);
                break;
                case 'Project':
                    Project = dimStorage.getDisplayValueByIndex(c);
                break;
            }
        }

       //Creating the New Dimension
       //Just keep the required dimensions and Comment the other dimensions

       // if(BussinessUnit)
       //     dim.add('BusinessUnit', BussinessUnit);
       // if(CostCenter)
       //     dim.add('Costcenter', CostCenter);
       // if(Department)
       //     dim.add('Department', Department);
        if(ItemGroup)
            dim.add('ItemGroup', ItemGroup);
        if(Project)
            dim.add('Project', Project);

        dimValue += dim.fields();

      //  if(BussinessUnit)
      //  {
      //      i++;
      //      dimValue += dim.fieldName(i);
      //      dimValue += dim.valueIndex(i);
      //  }
      //  if(CostCenter)
      //  {
      //      i++;
      //      dimValue += dim.fieldName(i);
      //      dimValue += dim.valueIndex(i);
      //  }
      //  if(Department)
      //  {
      //      i++;
      //      dimValue += dim.fieldName(i);
      //      dimValue += dim.valueIndex(i);
      //  }
        if(ItemGroup)
        {
            i++;
            dimValue += dim.fieldName(i);
            dimValue += dim.valueIndex(i);
        }
        if(Project)
        {
            i++;
            dimValue += dim.fieldName(i);
            dimValue += dim.valueIndex(i);
        }

        //Below code will get the new dimension
        DimensionDefault = AxdDimensionUtil::getDimensionAttributeValueSetId(dimValue);

        inventTable = inventTable::find(inventTableselect.ItemId,true);
        inventTable.DefaultDimension = DimensionDefault;

        inventTable.update();
    }
    ttsCommit;

    info("Updation completed");
}

 

Below Code snippet is used to update the Item,Customer and Vendor :


static void ItemDimUpdate(Args _args)
{
    InventTable inventTable;
    Struct dim = new Struct();
    container dimValue;
    DimensionDefault DimensionDefault;
    ;  

    dim.add('BusinessUnit', '002');
    dim.add('CostCenter', '007');
    dim.add('Department', '022');
    dim.add('ItemGroup', 'Audio Test');
    dim.add('Project', '000002');  

    dimValue += dim.fields();
    dimValue += dim.fieldName(1);
    dimValue += dim.valueIndex(1);
    dimValue += dim.fieldName(2);
    dimValue += dim.valueIndex(2);
    dimValue += dim.fieldName(3);
    dimValue += dim.valueIndex(3);
    dimValue += dim.fieldName(4);
    dimValue += dim.valueIndex(4);
    dimValue += dim.fieldName(5);
    dimValue += dim.valueIndex(5);  

    ttsBegin;  

    DimensionDefault = AxdDimensionUtil::getDimensionAttributeValueSetId(dimValue);
    inventTable = inventTable::find("A0001",true);
    inventTable.DefaultDimension = DimensionDefault;
    inventTable.update();  

    ttsCommit;  

}