Tuesday, November 16, 2010

Creating a new Item through Code

For Creating a new Item in AX 2009 we have to make a entry in four imp tables
they are
1) InventTable
2) InventTableModule
3) InventItemLocation
4) InventTxt

Below is a simple job which will create a new Item in AX 2009

static void Item(Args _args)
{
     InventTable inventTable;
     InventTableModule inventTableModule;
     InventItemLocation inventItemLocation;
     InventTxt inventTxt;
     int counter;
     ;
     ttsbegin();
     inventTable.initValue();
     inventTable.ItemId = "NIK-1000";
     inventTable.ItemGroupId = "Television";
     inventTable.ItemName = "LCD Plasma";
     inventTable.ModelGroupId = "STD Cost";
     inventTable.DimGroupId = "N-W";
     inventTable.ItemType = ItemType::Item;
     if(inventTable.validatewrite())
    {
         inventTable.insert();
    }
    for(counter=0; counter<=3; counter++)
   {
       inventTableModule.ItemId = inventTable.ItemId;
       inventTableModule.ModuleType = counter;
       inventTableModule.initValue();
       if(inventTableModule.validatewrite())
      {
          inventTableModule.insert();
      }
   }
   inventItemLocation.ItemId = inventTable.ItemId;
   inventItemLocation.inventDimId = InventDim::inventDimIdBlank();
   inventItemLocation.initValue();
   if(inventItemLocation.validatewrite())
  {
       inventItemLocation.insert();
  }
  inventTxt.ItemId = inventTable.ItemId;
  inventTxt.Txt = "LCD Plasma Television";
  if(inventItemLocation.validatewrite())
 {
     inventTxt.insert();
 }
 ttscommit();
 info(" New Item created succesfully");
}

No comments:

Post a Comment