Before using this code write your logic to read the CSV file using COMMAIO and get the container and pass to the below method.
And I created the Macro with the position numbers that i used in the below code.
I am using the AX classes to save the records into the Tables.
In AX2012 we have to create the Records for ECOResProduct.
ECOResProduct is the abstract Table and the following tables are inherited from this.
ECORESProductMaster,EcoResdistinctProduct.
When we are creating the new product in form if you select the productsubtype as productMaster then we have to insert into the ECORESProductMaster and we have to pass this recid into the inventTable.
When the productSubtype is Products then we have to use EcoResdistinctProduct and pass the recid to inventTable.
Below I am using the Products.
Macro:-
//InventTable
#define.InventTable_ItemId_ColumnNum(1)
#define.InventTable_PrimaryVendorId_ColumnNum(2)
#define.InventTable_NetWeight_ColumnNum(3)
#define.InventTable_UnitVolume_ColumnNum(4)
#define.InventTable_AltItemId_ColumnNum(5)
#define.InventTable_Intracode_ColumnNum(6)
#define.InventTable_ABCRevenue_ColumnNum(7)
#define.InventTable_NameAlias_ColumnNum(8)
#define.InventTable_Classification_ColumnNum(9)
#define.InventTable_Integration_ColumnNum(10)
//InventItemLocation columns
#define.InventItemLocation_ItemId_ColumnNum(11)
//Invent GroupItem
#define.InventItemGroupItem_ItemId_ColumnNum(12)
#define.InventItemGroupItem_ItemGroupId_ColumnNum(13)
//InventModelGroupItem
#define.InventModelGroupItem_ItemId_ColumnNum(14)
//ECOResProduct translation for english
#define.EcoResProductTranslationENG_Description_ColumnNum(15)
#define.EcoResProductTranslationENG_Name_ColumnNum(16)
//InventItemPurchSetup for default order settings
#define.InventItemPurch_ItemId_ColumnNum(17)
//inventItemInventSetup for Default order settings
#define.InventItemInvent_ItemId_ColumnNum(18)
#define.InventItemInvent_LowestQty_ColumnNum(19)
#define.InventItemInvent_HighestQty_ColumnNum(20)
#define.InventItemInvent_StandardQty_ColumnNum(21)
//InventItemSupplySetup
#define.InventItemSetupSupplytype_ItemId_ColumnNum(22)
Public class Krishh_ImportItem
{
//Macro which contains the column positions.
#ItemImport
AxInventTable axInventTable;
AxInventItemGroupItem axInventGroupItem;
AxInventModelGroupItem axInventModelGroupItem;
AxEcoResProductTranslation axProductTranslation;
AxInventItemInventSetup axInventItemInventSetup;
AxInventItemPurchSetup axInventItemPurchSetup;
InventItemSetupSupplyType inventItemSetupSupplyType;
EcoResDistinctProduct ecoResDistictProduct;
}
protected void createInventTable(container _conLine)
{
ItemId itemId;
InventTable inventTable;
InventItemGroupItem inventItemGroupItem;
;
itemId = this.getLineValue(_conLine,#InventTable_ItemId_ColumnNum);
inventTable= InventTable::find(itemId);
if(!inventTable)
{
ecoResDistictProduct.clear();
ecoResDistictProduct.initValue();
ecoResDistictProduct.DisplayProductNumber=itemId;
ecoResDistictProduct.ProductType=ecoResProductType::Item;
ecoResDistictProduct.SearchName=this.getLineValue(_conLine,#InventTable_NameAlias_ColumnNum);
ecoResDistictProduct.insert();
axInventTable=axInventTable::construct();
axInventTable.parmItemId(this.getLineValue(_conLine,#InventTable_ItemId_ColumnNum));
axInventTable.parmItemType(ItemType::Item);
axInventTable.parmPrimaryVendorId(this.getLineValue(_conLine,#InventTable_PrimaryVendorId_ColumnNum));
axInventTable.parmNetWeight(this.getLineValue(_conLine,#InventTable_NetWeight_ColumnNum));
axInventTable.parmProduct(ecoResDistictProduct.RecId);
axInventTable.parmUnitVolume(this.getLineValue(_conLine,#InventTable_UnitVolume_ColumnNum));
axInventTable.parmUseAltItemId(ItemNumAlternative::Always);
axInventTable.parmAltItemId(this.getLineValue(_conLine,#InventTable_AltItemId_ColumnNum));
axInventTable.parmIntracode(this.getLineValue(_conLine,#InventTable_Intracode_ColumnNum));
axInventTable.parmABCRevenue(this.getLineValue(_conLine,#InventTable_ABCRevenue_ColumnNum));
axInventTable.parmNameAlias(this.getLineValue(_conLine,#InventTable_NameAlias_ColumnNum));
axInventTable.parmClassification(this.getLineValue(_conLine,#InventTable_Classification_ColumnNum));
//TODO uncomment once the parm methods where builded
// axInventTable.parmIntegration(this.getLineValue(_conLine,#InventTable_Integration_ColumnNum));
// axInventTable.parmRevisionId(this.getLineValue(_conLine,#InventTable_RevisionId_ColumnNum));
//InventItemInventSetup
axInventItemInventSetup=AxInventItemInventSetup::construct();
axInventItemInventSetup.parmItemId(itemId);
axInventItemInventSetup.parmLowestQty(this.getLineValue(_conLine,#InventItemInvent_LowestQty_ColumnNum));
axInventItemInventSetup.parmHighestQty(this.getLineValue(_conLine,#InventItemInvent_HighestQty_ColumnNum));
axInventItemInventSetup.parmStandardQty(this.getLineValue(_conLine,#InventItemInvent_StandardQty_ColumnNum));
axInventTable.axInventItemInventSetup(axInventItemInventSetup);
//
//////InventPurchSetup
axInventItemPurchSetup=AxInventItemPurchSetup::construct();
axInventItemPurchSetup.parmItemId(itemId);
axInventTable.axInventItemPurchSetup(axInventItemPurchSetup);
axInventTable.save();
//InventGroup Item
axInventGroupItem=AxInventItemGroupItem::construct();
axInventGroupItem.parmItemId(itemId);
axInventGroupItem.parmItemGroupId(this.getLineValue(_conLine,#InventItemGroupItem_ItemGroupId_ColumnNum));
axInventGroupItem.parmItemGroupDataAreaId(curext());
axInventGroupItem.save();
//InventModelGroupItem
axInventModelGroupItem=AxInventModelGroupItem::construct();
axInventModelGroupItem.parmItemId(itemId);
axInventModelGroupItem.parmModelGroupId("Std Cost");
axInventModelGroupItem.parmModelGroupDataAreaId(curext());
axInventModelGroupItem.save();
//Product Translation
axProductTranslation=AxEcoResProductTranslation::construct();
axProductTranslation.parmDescription(this.getLineValue(_conLine,#EcoResProductTranslationENG_Description_ColumnNum));
axProductTranslation.parmName(this.getLineValue(_conLine,#EcoResProductTranslationENG_Name_ColumnNum));
axProductTranslation.parmProduct(ecoResDistictProduct.RecId);
axProductTranslation.save();
//InventItemSetupSupplyType
inventItemSetupSupplyType.clear();
inventItemSetupSupplyType.initValue();
inventItemSetupSupplyType.DefaultOrderType=ReqPOType::Purch;
inventItemSetupSupplyType.ItemId=itemId;
inventItemSetupSupplyType.ItemDataAreaId=curext();
inventItemSetupSupplyType.insert();
}
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.