web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :

Create new item using X++ in AX 2009

Abdel Fatah Ahmed Profile Picture Abdel Fatah Ahmed
Sometimes we need to add new items into the system but we have alot of itemes to add it by our hands then we need X++ code to simplify the proccess for example we have excell file contain this items :

// This can be called to create a new item , for example CreateNewItem('AA01');
 void CreateNewItem(ItemId _itemId,ItemName _itemName,BOMUnitId UOM, ItemGroupId _itemGroup ,InventDimGroupId _dimGroup= 'Standard',InventModelGroupId _modelGroup='Standard', Price price1)
{
   //InventTable         inventTable;
    InventTableModule   inventTableModule;
    InventItemLocation  inventItemLocation;
    ;
    ttsbegin;
    // Master record in InventTable
    select forupdate inventTable;
    inventTable.initValue();
    // If InventTable has other mandatory fields in addition to
    // ItemGroupId and ItemId, they should be defined here
    inventTable.ItemGroupId = _itemGroup;
    inventTable.ModelGroupId=_modelGroup;
    inventTable.DimGroupId=_dimGroup;
    inventTable.BOMUnitId= UOM;
    inventTable.ItemId = _itemId;
    inventTable.ItemName = _itemName;
    inventTable.ItemType = ItemType::Item;
    inventTable.ItemIdCompany="";
    // You can put default DimGroupId, ModelGroupId, etc. here
    inventTable.insert();
    // InventItemLocation for default dimension
    select forupdate inventItemLocation;
    inventItemLocation.initValue();
    inventItemLocation.ItemId = _itemId;
    inventItemLocation.InventDimId = InventDim::inventDimIdBlank();
    inventItemLocation.insert();
    // Three records in InventTableModule (for Cost, Purchase and Sales)
    //  you can also set the price, unit and other values here
    select forupdate inventTableModule;
    // Cost
    inventTableModule.initValue();
    inventTableModule.ItemId = _itemId;
    inventTableModule.Price = price1;
    inventTableModule.UnitId=UOM;
    inventTableModule.ModuleType = ModuleInventPurchSales::Invent;
    inventTableModule.insert();
    // Purchase order
    inventTableModule.initValue();
    inventTableModule.ItemId = _itemId;
    inventTableModule.Price = price1;
    inventTableModule.UnitId=UOM;
    inventTableModule.ModuleType = ModuleInventPurchSales::Purch;
    inventTableModule.insert();
    // Sales order
    inventTableModule.initValue();
    inventTableModule.ItemId = _itemId;
    inventTableModule.Price = price1;
    inventTableModule.UnitId=UOM;
    inventTableModule.OverDeliveryPct=0;
    inventTableModule.UnderDeliveryPct=100;
    inventTableModule.ModuleType = ModuleInventPurchSales::Sales;
    inventTableModule.insert();

    ttscommit;
  }

Comments

*This post is locked for comments