Monday, December 26, 2016

Updating dimension group for an item in ax 2012

static void UpdatingDimensionGroup(Args _args)
{

     inventTable inventTable;
 
     ttsBegin;
    while select inventTable
    {
            InventTableInventoryDimensionGroups::updateDimensionGroupsForItem(curext(),      inventTable.itemid, EcoResStorageDimensionGroup::findByDimensionGroupName("XXX_SDG").RecId,    EcoResTrackingDimensionGroup::findByDimensionGroupName("XXX_TDG").RecId,inventtable.product);
    }
    ttsCommit;

}

Updating Site specific order settings of an item in ax 2012


    InventDim       inventDim,invDim;
    InventTable     inventTable;
    inventDimId inventDimId;
    InventItemPurchSetup    invPurch;
    InventItemSalesSetup    invSal;
    InventItemInventSetup   invInvent;
   
    while select inventTable
    {      
   
            invDim.clear();
            Select forUpdate invDim where invDim.InventSiteId == "AD" && invDim.InventLocationId == '' && InvDim.InventBatchId == '';
            if (!invDim)
            {
                invDim.InventBatchId     = '';
                invDim.InventLocationId  = '';
                invDim.InventSiteId      = "AD";                
                invDim = InventDim::findOrCreate(invDim);
            }
            inventDimId = invDim.InventDimId;

            // Delete existing dimensions
            delete_from invPurch where invPurch.ItemId == inventTable.ItemId &&
            invPurch.InventDimId != "AllBlank";              

            // Purchase Location Id
            invDim.clear();
            Select forUpdate invDim where invDim.InventSiteId == '' && invDim.InventLocationId == "AD-DRY" && InvDim.InventBatchId == '';
            if (!invDim)
            {
                invDim.InventBatchId     = '';
                invDim.InventLocationId  = "AD-DRY";
                invDim.InventSiteId      = '';
                invDim.initFromInventLocation(invDim.inventLocation());
                invDim = InventDim::findOrCreate(invDim);
            }
           
            // Dimension for Location
            invPurch.clear();
            invPurch.initFromDefault();
            invPurch.ItemId = inventTable.ItemId;
           
            invPurch.InventDimId = inventDimId;
            invPurch.InventDimIdDefault = invDim.InventDimId;
            invPurch.insert();
   
            delete_from invSal where invSal.ItemId == inventTable.ItemId &&
            invSal.InventDimId != "AllBlank";  
            invSal.clear();
            invSal.initFromDefault();
            invSal.ItemId = inventTable.ItemId;
           
            invSal.InventDimId = inventDimId;
            invSal.InventDimIdDefault = invDim.InventDimId;
            invSal.insert();
   
            delete_from invInvent where invInvent.ItemId == inventTable.ItemId &&
            invInvent.InventDimId != "AllBlank";
            invInvent.clear();
            invInvent.initFromDefault();
            invInvent.ItemId = inventTable.ItemId;
           
            invInvent.InventDimId = inventDimId;
            invInvent.InventDimIdDefault = invDim.InventDimId;
            invInvent.insert();
    }
   

Updating default order setting of an item in ax 2012


    InventTable inventTable;
    InventItemInventSetup inventItemInventSetup;
    InventItemPurchSetup inventItemPurchSetup;
    InventItemSalesSetup inventItemSalesSetup;
    InventDim inventDim;
    InventDimId dimId;

   ;
   ttsBegin;
    inventDim.initValue();
   inventDim.InventSiteId = "AD";
   inventDim = InventDim::findOrCreate(inventDim);
   dimId =  inventDim.inventDimId;
   while select inventTable
   {
        info(strFmt("%1",inventTable.ItemId));

    inventItemInventSetup.clear();
    inventItemPurchSetup.clear();
    inventItemSalesSetup.clear();

   select inventItemInventSetup where inventItemInventSetup.InventDimId == inventDim.inventDimId;
   if(!inventItemInventSetup)
    {
        //Site specific setup
       inventItemInventSetup.initValue();
       inventItemInventSetup.InventDimId = inventDim.inventDimId;
       inventItemInventSetup.ItemId = inventTable.ItemId;
       inventItemInventSetup.insert();
   }
   select inventItemPurchSetup where inventItemPurchSetup.InventDimId == inventDim.inventDimId;
   if(!inventItemPurchSetup)
   {
       inventItemPurchSetup.initValue();
       inventItemPurchSetup.InventDimId = inventDim.inventDimId;
       inventItemPurchSetup.ItemId = inventTable.ItemId;
       inventItemPurchSetup.insert();
   }
   select inventItemSalesSetup where inventItemSalesSetup.InventDimId == inventDim.inventDimId;
   if(!inventItemSalesSetup)
   {
       inventItemSalesSetup.initValue();
       inventItemSalesSetup.InventDimId = inventDim.inventDimId;
       inventItemSalesSetup.ItemId = inventTable.ItemId;
       inventItemSalesSetup.insert();
   }
    inventItemInventSetup.clear();
    inventItemPurchSetup.clear();
    inventItemSalesSetup.clear();
   //Default order settings
   inventItemInventSetup= inventItemInventSetup::findDefault(inventTable.itemId, true);
   inventItemInventSetup.InventDimIdDefault = inventDim.inventDimId;
   inventItemInventSetup.update();


   inventItemPurchSetup = inventItemPurchSetup::findDefault(inventTable.itemId, true);
   inventItemPurchSetup.InventDimIdDefault = inventDim.inventDimId;
   inventItemPurchSetup.update();


   inventItemSalesSetup= inventItemSalesSetup::findDefault(inventTable.itemId, true);
   inventItemSalesSetup.InventDimIdDefault = inventDim.inventDimId;
   inventItemSalesSetup.update();

    }
    ttsCommit;