Referecnce: http://community.dynamics.com/ax/f/33/t/37276.aspx
static void CreateNewItem(ItemId _itemId, ItemGroupId _itemGroup = '', ItemName _itemName = '')
{
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.ItemId = _itemId;
inventTable.ItemName = _itemName;
inventTable.ItemType = ItemType::Item;
// 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)
// Of course, you can also set the price, unit and other values here
select forupdate inventTableModule;
// Cost
inventTableModule.initValue();
inventTableModule.ItemId = _itemId;
inventTableModule.ModuleType = ModuleInventPurchSales::Invent;
inventTableModule.insert();
// Purchase order
inventTableModule.initValue();
inventTableModule.ItemId = _itemId;
inventTableModule.ModuleType = ModuleInventPurchSales::Purch;
inventTableModule.insert();
// Sales order
inventTableModule.initValue();
inventTableModule.ItemId = _itemId;
inventTableModule.ModuleType = ModuleInventPurchSales::Sales;
inventTableModule.insert();
ttscommit;
}
No comments:
Post a Comment