Monday, December 26, 2016

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;

No comments:

Post a Comment