static void UploadProductMaster(Args _args)
{
CommaTextIO csvFile;
container readCon;
counter icount,inserted;
Dialog dialog;
DialogField dfFileName;
FileName fileName;
InventTable inventTable;
EcoResProduct ecoResProduct;
EcoResProductMaster EcoResProductMaster;
EcoResProductTranslation ecoResProductTranslation;
InventModelGroupItem InventModelGroupItemLoc;
EcoResDistinctProductVariant EcoResDistinctProductVariant;
EcoResProductDimensionGroupProduct ecoResProductDimensionGroupProduct;
EcoResStorageDimensionGroupItem ecoResStorageDimensionGroupItem;
EcoResTrackingDimensionGroupItem ecoResTrackingDimensionGroupItem;
EcoResStorageDimensionGroupProduct ecoResStorageDimensionGroupProduct;
EcoResTrackingDimensionGroupProduct ecoResTrackingDimensionGroupProduct;
InventTableModule inventTableModule;
inventItemGroupItem inventItemGroupItem;
InventItemSetupSupplyType inventItemSetupSupplyType;
ecoResProductIdentifier ecoResProductIdentifier;
ItemId itemID ;
str name,Description,itemtype,productDimensionGroup,StorageDimensionGroup,TrackingDimensiongroup,modelGroupId,itemGroupId,unit,price,searchname;
inserted =0;
#File
dialog = new Dialog("Pick the file");
dfFileName = dialog.addField(extendedTypeStr("FilenameOpen"));
dialog.filenameLookupFilter(["All files", #AllFiles]);
if (dialog.run())
{
csvFile = new CommaTextIo(dfFileName.value(), 'r');
csvFile.inFieldDelimiter(',');
readCon = csvFile.read();
ttsBegin;
while(csvFile.status() == IO_Status::OK)
{
readCon = csvFile.read();
if(readCon)
{
icount++;
itemId = "ABC9";//conPeek(readCon,1);
name = "ABC9name";//conPeek(readCon,2);
searchname = "searchname";
Description = "DEscription";
itemtype = "BOM";
productDimensionGroup = "PG_4";//conPeek(readCon,3);
StorageDimensionGroup = "PDG_001";//conPeek(readCon,4);
TrackingDimensiongroup = "PDG_001";//conPeek(readCon,5);
modelGroupId = "FIFO";//conPeek(readCon,6);
itemGroupId = "Television";//conPeek(readCon,7);
unit = "ea";//conPeek(readCon,8);
price = "0";//conPeek(readCon,9);
select firstOnly ecoResProduct where EcoResProduct.DisplayProductNumber == itemId;
if(!ecoResProduct)
{
EcoResProductMaster.initValue();
EcoResProductMaster.DisplayProductNumber = itemId;
EcoResProductMaster.SearchName = searchname;
EcoResProductMaster.ProductType = EcoResProductType::Item;
EcoResProductMaster.VariantConfigurationTechnology = EcoResVariantConfigurationTechnologyType::PredefinedVariants;
EcoResProductMaster.insert();
ecoResProduct= EcoResProductMaster;
}
ecoResProductTranslation.Product = ecoResProduct.RecId;
ecoResProductTranslation.Name = name;
EcoResProductTranslation.Description = Description;
ecoResProductTranslation.setDefaultLanguage();
ecoResProductTranslation.insert();
EcoResDistinctProductVariant.DisplayProductNumber = itemId ;
EcoResDistinctProductVariant.ProductMaster = ecoResProduct.RecId;
EcoResDistinctProductVariant.ProductType = ecoResProduct.ProductType;
EcoResDistinctProductVariant.insert();
inventTable.initValue();
inventTable.initFromEcoResProduct(ecoResProduct);
inventTable.ItemId = itemId;
inventTable.NameAlias = ecoResProduct.SearchName;
if(ItemType == "BOM")
inventTable.PmfProductType = PmfProductType::BOM;
else
inventTable.PmfProductType = PmfProductType::None;
inventTable.insert(true);
inventTableModule.initValue();
inventTableModule.ItemId = inventTable.ItemId;
inventTableModule.ModuleType = ModuleInventPurchSales::Invent;
InventTableModule.UnitId = unit;
InventTableModule.Price = any2real(Price);
inventTableModule.insert();
inventTableModule.initValue();
inventTableModule.ItemId = inventTable.ItemId;
inventTableModule.ModuleType = ModuleInventPurchSales::Purch;
InventTableModule.UnitId = unit;
InventTableModule.Price = any2real(Price);
inventTableModule.insert();
inventTableModule.initValue();
inventTableModule.ItemId = inventTable.ItemId;
inventTableModule.ModuleType = ModuleInventPurchSales::Sales;
InventTableModule.UnitId = unit;
InventTableModule.Price = any2real(Price);
inventTableModule.insert();
//Create inventItemLocation
InventItemLocation::createDefault(inventTable.ItemId);
// Creates a new item default order type for the product that is released.
inventItemSetupSupplyType.initValue();
inventItemSetupSupplyType.ItemId = inventTable.ItemId;
inventItemSetupSupplyType.ItemDataAreaId = inventTable.DataAreaId;
inventItemSetupSupplyType.insert();
//create relationship tables to dimension groups.
ecoResStorageDimensionGroupProduct = EcoResStorageDimensionGroupProduct::findByProduct(ecoResProduct.RecId);
ecoResTrackingDimensionGroupProduct = EcoResTrackingDimensionGroupProduct::findByProduct(ecoResProduct.RecId);
if (ecoResStorageDimensionGroupProduct.RecId)
{
// mandatory storage dimension group for the product
ecoResStorageDimensionGroupItem.ItemDataAreaId = inventTable.DataAreaId;
ecoResStorageDimensionGroupItem.ItemId = inventTable.ItemId;
ecoResStorageDimensionGroupItem.StorageDimensionGroup = ecoResStorageDimensionGroupProduct.StorageDimensionGroup;
ecoResStorageDimensionGroupItem.insert();
}
if (ecoResTrackingDimensionGroupProduct.RecId)
{
// mandatory tracking dimension group for the product
ecoResTrackingDimensionGroupItem.ItemDataAreaId = inventTable.DataAreaId;
ecoResTrackingDimensionGroupItem.ItemId = inventTable.ItemId;
ecoResTrackingDimensionGroupItem.TrackingDimensionGroup = ecoResTrackingDimensionGroupProduct.TrackingDimensionGroup;
ecoResTrackingDimensionGroupItem.insert();
}
InventModelGroupItemLoc.ItemDataAreaId = inventTable.dataAreaId;
InventModelGroupItemLoc.ItemId = inventTable.ItemId;
InventModelGroupItemLoc.ModelGroupId =modelGroupId;
InventModelGroupItemLoc.ModelGroupDataAreaId = curext();
InventModelGroupItemLoc.initValue();
InventModelGroupItemLoc.insert();
//Item group
inventItemGroupItem.clear();
inventItemGroupItem.initValue();
inventItemGroupItem.ItemDataAreaId = inventTable.dataAreaId;
inventItemGroupItem.ItemId = inventTable.ItemId;
inventItemGroupItem.ItemGroupId = itemGroupId;
inventItemGroupItem.ItemGroupDataAreaId = curext();
inventItemGroupItem.insert();
//write product to dimension group relation
ecoResProductDimensionGroupProduct.initFromProduct(ecoResProduct);
ecoResProductDimensionGroupProduct.ProductDimensionGroup = EcoResProductDimensionGroup::findByDimensionGroupName(productDimensionGroup).RecId;// "PG_4";
ecoResProductDimensionGroupProduct.insert();
ecoResStorageDimensionGroupItem.initValue();
ecoResStorageDimensionGroupItem.ItemDataAreaId = inventTable.dataAreaId;
ecoResStorageDimensionGroupItem.ItemId = inventTable.ItemId;
ecoResStorageDimensionGroupItem.StorageDimensionGroup = EcoResStorageDimensionGroup::findByDimensionGroupName(StorageDimensionGroup).RecId;
ecoResStorageDimensionGroupItem.insert();
ecoResTrackingDimensionGroupItem.initValue();
ecoResTrackingDimensionGroupItem.ItemDataAreaId = inventTable.dataAreaId;
ecoResTrackingDimensionGroupItem.ItemId = inventTable.ItemId;
ecoResTrackingDimensionGroupItem.TrackingDimensionGroup = EcoResTrackingDimensionGroup::findByDimensionGroupName(TrackingDimensiongroup).RecId;
ecoResTrackingDimensionGroupItem.insert();
ecoResProductIdentifier.clear();
ecoResProductIdentifier.initValue();
ecoResProductIdentifier.ProductNumber = itemId;
ecoResProductIdentifier.Product = EcoResProductMaster.RecId; //ecoResProductMaster.RecId;
ecoResProductIdentifier.insert();
}
}
ttsCommit;
}
}
{
CommaTextIO csvFile;
container readCon;
counter icount,inserted;
Dialog dialog;
DialogField dfFileName;
FileName fileName;
InventTable inventTable;
EcoResProduct ecoResProduct;
EcoResProductMaster EcoResProductMaster;
EcoResProductTranslation ecoResProductTranslation;
InventModelGroupItem InventModelGroupItemLoc;
EcoResDistinctProductVariant EcoResDistinctProductVariant;
EcoResProductDimensionGroupProduct ecoResProductDimensionGroupProduct;
EcoResStorageDimensionGroupItem ecoResStorageDimensionGroupItem;
EcoResTrackingDimensionGroupItem ecoResTrackingDimensionGroupItem;
EcoResStorageDimensionGroupProduct ecoResStorageDimensionGroupProduct;
EcoResTrackingDimensionGroupProduct ecoResTrackingDimensionGroupProduct;
InventTableModule inventTableModule;
inventItemGroupItem inventItemGroupItem;
InventItemSetupSupplyType inventItemSetupSupplyType;
ecoResProductIdentifier ecoResProductIdentifier;
ItemId itemID ;
str name,Description,itemtype,productDimensionGroup,StorageDimensionGroup,TrackingDimensiongroup,modelGroupId,itemGroupId,unit,price,searchname;
inserted =0;
#File
dialog = new Dialog("Pick the file");
dfFileName = dialog.addField(extendedTypeStr("FilenameOpen"));
dialog.filenameLookupFilter(["All files", #AllFiles]);
if (dialog.run())
{
csvFile = new CommaTextIo(dfFileName.value(), 'r');
csvFile.inFieldDelimiter(',');
readCon = csvFile.read();
ttsBegin;
while(csvFile.status() == IO_Status::OK)
{
readCon = csvFile.read();
if(readCon)
{
icount++;
itemId = "ABC9";//conPeek(readCon,1);
name = "ABC9name";//conPeek(readCon,2);
searchname = "searchname";
Description = "DEscription";
itemtype = "BOM";
productDimensionGroup = "PG_4";//conPeek(readCon,3);
StorageDimensionGroup = "PDG_001";//conPeek(readCon,4);
TrackingDimensiongroup = "PDG_001";//conPeek(readCon,5);
modelGroupId = "FIFO";//conPeek(readCon,6);
itemGroupId = "Television";//conPeek(readCon,7);
unit = "ea";//conPeek(readCon,8);
price = "0";//conPeek(readCon,9);
select firstOnly ecoResProduct where EcoResProduct.DisplayProductNumber == itemId;
if(!ecoResProduct)
{
EcoResProductMaster.initValue();
EcoResProductMaster.DisplayProductNumber = itemId;
EcoResProductMaster.SearchName = searchname;
EcoResProductMaster.ProductType = EcoResProductType::Item;
EcoResProductMaster.VariantConfigurationTechnology = EcoResVariantConfigurationTechnologyType::PredefinedVariants;
EcoResProductMaster.insert();
ecoResProduct= EcoResProductMaster;
}
ecoResProductTranslation.Product = ecoResProduct.RecId;
ecoResProductTranslation.Name = name;
EcoResProductTranslation.Description = Description;
ecoResProductTranslation.setDefaultLanguage();
ecoResProductTranslation.insert();
EcoResDistinctProductVariant.DisplayProductNumber = itemId ;
EcoResDistinctProductVariant.ProductMaster = ecoResProduct.RecId;
EcoResDistinctProductVariant.ProductType = ecoResProduct.ProductType;
EcoResDistinctProductVariant.insert();
inventTable.initValue();
inventTable.initFromEcoResProduct(ecoResProduct);
inventTable.ItemId = itemId;
inventTable.NameAlias = ecoResProduct.SearchName;
if(ItemType == "BOM")
inventTable.PmfProductType = PmfProductType::BOM;
else
inventTable.PmfProductType = PmfProductType::None;
inventTable.insert(true);
inventTableModule.initValue();
inventTableModule.ItemId = inventTable.ItemId;
inventTableModule.ModuleType = ModuleInventPurchSales::Invent;
InventTableModule.UnitId = unit;
InventTableModule.Price = any2real(Price);
inventTableModule.insert();
inventTableModule.initValue();
inventTableModule.ItemId = inventTable.ItemId;
inventTableModule.ModuleType = ModuleInventPurchSales::Purch;
InventTableModule.UnitId = unit;
InventTableModule.Price = any2real(Price);
inventTableModule.insert();
inventTableModule.initValue();
inventTableModule.ItemId = inventTable.ItemId;
inventTableModule.ModuleType = ModuleInventPurchSales::Sales;
InventTableModule.UnitId = unit;
InventTableModule.Price = any2real(Price);
inventTableModule.insert();
//Create inventItemLocation
InventItemLocation::createDefault(inventTable.ItemId);
// Creates a new item default order type for the product that is released.
inventItemSetupSupplyType.initValue();
inventItemSetupSupplyType.ItemId = inventTable.ItemId;
inventItemSetupSupplyType.ItemDataAreaId = inventTable.DataAreaId;
inventItemSetupSupplyType.insert();
//create relationship tables to dimension groups.
ecoResStorageDimensionGroupProduct = EcoResStorageDimensionGroupProduct::findByProduct(ecoResProduct.RecId);
ecoResTrackingDimensionGroupProduct = EcoResTrackingDimensionGroupProduct::findByProduct(ecoResProduct.RecId);
if (ecoResStorageDimensionGroupProduct.RecId)
{
// mandatory storage dimension group for the product
ecoResStorageDimensionGroupItem.ItemDataAreaId = inventTable.DataAreaId;
ecoResStorageDimensionGroupItem.ItemId = inventTable.ItemId;
ecoResStorageDimensionGroupItem.StorageDimensionGroup = ecoResStorageDimensionGroupProduct.StorageDimensionGroup;
ecoResStorageDimensionGroupItem.insert();
}
if (ecoResTrackingDimensionGroupProduct.RecId)
{
// mandatory tracking dimension group for the product
ecoResTrackingDimensionGroupItem.ItemDataAreaId = inventTable.DataAreaId;
ecoResTrackingDimensionGroupItem.ItemId = inventTable.ItemId;
ecoResTrackingDimensionGroupItem.TrackingDimensionGroup = ecoResTrackingDimensionGroupProduct.TrackingDimensionGroup;
ecoResTrackingDimensionGroupItem.insert();
}
InventModelGroupItemLoc.ItemDataAreaId = inventTable.dataAreaId;
InventModelGroupItemLoc.ItemId = inventTable.ItemId;
InventModelGroupItemLoc.ModelGroupId =modelGroupId;
InventModelGroupItemLoc.ModelGroupDataAreaId = curext();
InventModelGroupItemLoc.initValue();
InventModelGroupItemLoc.insert();
//Item group
inventItemGroupItem.clear();
inventItemGroupItem.initValue();
inventItemGroupItem.ItemDataAreaId = inventTable.dataAreaId;
inventItemGroupItem.ItemId = inventTable.ItemId;
inventItemGroupItem.ItemGroupId = itemGroupId;
inventItemGroupItem.ItemGroupDataAreaId = curext();
inventItemGroupItem.insert();
//write product to dimension group relation
ecoResProductDimensionGroupProduct.initFromProduct(ecoResProduct);
ecoResProductDimensionGroupProduct.ProductDimensionGroup = EcoResProductDimensionGroup::findByDimensionGroupName(productDimensionGroup).RecId;// "PG_4";
ecoResProductDimensionGroupProduct.insert();
ecoResStorageDimensionGroupItem.initValue();
ecoResStorageDimensionGroupItem.ItemDataAreaId = inventTable.dataAreaId;
ecoResStorageDimensionGroupItem.ItemId = inventTable.ItemId;
ecoResStorageDimensionGroupItem.StorageDimensionGroup = EcoResStorageDimensionGroup::findByDimensionGroupName(StorageDimensionGroup).RecId;
ecoResStorageDimensionGroupItem.insert();
ecoResTrackingDimensionGroupItem.initValue();
ecoResTrackingDimensionGroupItem.ItemDataAreaId = inventTable.dataAreaId;
ecoResTrackingDimensionGroupItem.ItemId = inventTable.ItemId;
ecoResTrackingDimensionGroupItem.TrackingDimensionGroup = EcoResTrackingDimensionGroup::findByDimensionGroupName(TrackingDimensiongroup).RecId;
ecoResTrackingDimensionGroupItem.insert();
ecoResProductIdentifier.clear();
ecoResProductIdentifier.initValue();
ecoResProductIdentifier.ProductNumber = itemId;
ecoResProductIdentifier.Product = EcoResProductMaster.RecId; //ecoResProductMaster.RecId;
ecoResProductIdentifier.insert();
}
}
ttsCommit;
}
}
Hi,
ReplyDeleteYour code works fine but what if i need to create a product using template..?
How can i assign template at the time of product creation..?
Thanks,
Kartik