I have a question regarding the service for creating products in AX2012. I have to import products from a file, and create them using the service (see example below). I only want to call the create on the service once, and not for each record, my problem is that when i call the ecoResProduct.createProduct().add(product) I get an error that the product key already exist.
Any suggestions ??
I have the following code:
EcoResEcoResProduct ecoResProduct;
EcoResEcoResProduct_Product product;
EcoResProductService ecoresPRoductService;
ecoresPRoductService=EcoResProductService::construct();
ecoResProduct=new EcoResEcoResProduct();
if (d.run())
{
file = new CommaIo(df1.value(), ‘r’);
file.inFieldDelimiter(’;’);
while (file.status() == IO_Status::Ok)
{
readCon = file.read();
//This object intitializing should be iterated for multiple records.
product=new EcoResEcoResProduct_Product_Master();
product.parmDisplayProductNumber(strLRTrim(conPeek(readCon,1)));
product.parmProductType(EcoResProductType::Item);
product.parmSearchName(strLRTrim(conPeek(readCon,2)));
ecoResProduct.createProduct().add(product);
}
ecoresPRoductService.create(ecoResProduct);
}