creating multiple items using the ecoresecoresproduct service by calling one time create Function. This code was written by my friend Jesper Clausen, I personally thanks hims for providing this code.
static void ImportProducts(Args _args)
{
EcoResEcoResProduct ecoResEcoResProduct;
EcoResEcoResProduct_Product_Distinct ProdDist;
EcoResEcoResProduct_translation translation;
EcoResEcoResProduct_Identifier identifier;
EcoResEcoResProduct_ProductDimGroup prodDimGroup;
EcoResEcoResProduct_StorageDimGroup storDimGroup;
EcoResEcoResProduct_TrackingDimGroup tracDimGroup;
EcoResProductService ecoresPRoductService;
CommaIo file;
container readCon;
Dialog d;
DialogField df1, df2;
EcoResProductDisplayProductNumber ProductDisplayProductNumber;
// Create a comma separated file as input with col1 = product and col2 = description
and remaining fields.
;
d = new Dialog("Import items");
df1 = d.addField(ExtendedTypeStr("FilenameOpen"));
ecoresPRoductService=EcoResProductService::construct();
ecoResEcoResProduct= new EcoResEcoResProduct();
if (d.run())
{
file = new CommaIo(df1.value(), 'r');
file.inFieldDelimiter(';');
while (file.status() == IO_Status::Ok)
{
readCon = file.read();
ProdDist = new EcoResEcoResProduct_Product_Distinct();
ProdDist.parmDisplayProductNumber(strLRTrim(conPeek(readCon,1)));
ProdDist.parmProductType(EcoResProductType::Item);
ProdDist.parmSearchName(strLRTrim(conPeek(readCon,2)));
// Create the translation object
translation = ProdDist.createTranslation().addNew();
translation.parmDescription(strLRTrim(conPeek(readCon,2)));
translation.parmLanguageId("en-us");
translation.parmName(strLRTrim(conPeek(readCon,1)));
// Create the identifier object
Identifier = ProdDist.createIdentifier().addNew();
identifier.parmProductNumber(strLRTrim(conPeek(readCon,1)));
// Create the StorageDimgroup object
storDimGroup = ProdDist.createStorageDimGroup().addNew();
storDimGroup.parmProduct(strLRTrim(conPeek(readCon,1)));
storDimGroup.parmStorageDimensionGroup("Con-Dim");
// Create the TrackingDimGroup object
tracDimGroup = ProdDist.createTrackingDimGroup().addNew();
tracDimGroup.parmProduct(strLRTrim(conPeek(readCon,1)));
tracDimGroup.parmTrackingDimensionGroup("Lean-Dim1");
// checking this product is already Exists or not .
if(ecoResEcoResProduct.existsProduct())
{
ecoResEcoResProduct.parmProduct().add(ProdDist);
}
else
{
ecoResEcoResProduct.createProduct().add(ProdDist);
}
}
// call create function to create products.
ecoresPRoductService.create(ecoResEcoResProduct);