In AX2012 we
have to create the Records for ECOResProduct.
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.
Ax classes are used to create the records for ECOResProduct
public class ProductMasterUpload
extends RunBase
{
CommaIo csvFile;
Filename filename;
DialogField dialogFilename,dialogcheckbox,dialogFromDate,dialogledger;
container readCon;
counter icount,inserted;
Amount amount;
TransDate TransactionDate,Fromdate,TransDate,StartDate,enddate,reversedate;
NoYesID NoYes;
Ledgerjournalnameid
Ledgerjournalnameid1,LedgerJournalNameId;
int cutoffdays,prevcutoffdays;
Amount AmountDB,AmountCR,CrCutOffAmountCalc,DrCutOffAmountCalc;
str AccountNum,date1;
args args;
EcoResProductVariantDimensionValue
EcoResProductVariantDimensionValue;
RefRecId ecoResDistinctProductVariantRecId;
EcoResProductReleaseManagerBase releaseManager;
container productDimensions;
#define.CurrentVersion(2)
#localmacro.CurrentList
filename,
insertIncorrectRecords,
#endmacro
#localmacro.ListVersion1
filename,
insertIncorrectRecords
#endmacro
#File
}
public Object dialog()
{
DialogRunbase dialog =
super();
;
dialogFilename = dialog.addField(extendedTypeStr(FilenameOpen));
dialogFilename.value(filename);
dialog.filenameLookupFilter(["All files",
#AllFiles]);
return dialog;
}
public boolean getFromDialog()
{
filename = dialogFilename.value();
return true;
}
static void main(Args args)
{
ProductMasterUpload ProductMasterUpload;
ledgerJournalTrans ledgerJournalTrans;
;
ProductMasterUpload =
new ProductMasterUpload();
if(ProductMasterUpload.prompt())
{
ProductMasterUpload.ProductMasterNew();
}
}
private void ProductMasterNew()
{
CommaTextIo file;
container rec;
// ProductMaster
EcoResProductMaster ecoResProductMaster;
EcoResProductIdentifier ecoResProductIdentifier;
EcoResProductDimensionGroupProduct ecoResProductDimensionGroupProduct;
EcoResProductMasterModelingPolicy ecoResProductMasterModelingPolicy;
EcoResStorageDimensionGroupProduct ecoResStorageDimensionGroupProduct;
EcoResTrackingDimensionGroupProduct ecoResTrackingDimensionGroupProduct;
EcoResConfiguration ecoResConfiguration;
EcoResSize ecoResSize;
EcoResStyle ecoResStyle;
EcoResColor ecoResColor;
EcoResProductMasterConfiguration ecoResProductMasterConfiguration;
EcoResProductMasterSize ecoResProductMasterSize;
EcoResProductMasterStyle ecoResProductMasterStyle;
EcoResProductMasterColor ecoResProductMasterColor;
EcoResDistinctProductVariant ecoResDistinctProductVariant;
EcoResProductVariantConfiguration ecoResProductVariantConfiguration;
EcoResProductVariantSize ecoResProductVariantSize;
EcoResProductVariantStyle ecoResProductVariantStyle;
EcoResProductVariantColor ecoResProductVariantColor;
InventTable inventTable;
InventTableModule inventTableModule;
InventItemSetupSupplyType inventItemSetupSupplyType;
EcoResStorageDimensionGroupItem ecoResStorageDimensionGroupItem;
EcoResTrackingDimensionGroupItem ecoResTrackingDimensionGroupItem;
InventModelGroupItem inventModelGroupItem;
InventItemGroupItem inventItemGroupItem;
InventDim inventDim;
InventDimCombination inventDimCombination;
InventDim inventDim_InventSiteId;
InventDim inventDim_InventLocationId;
ItemId itemId;
EcoResProduct EcoResProduct;
EcoResCategory EcoResCategory;
EcoResCategoryHierarchy EcoResCategoryHierarchy;
EcoResCategoryAttribute ecoResCategoryAttribute;
EcoResAttribute ecoResAttribute;
EcoResProductAttributeValue EcoResProductAttributeValue;
str name,productDimensionGroup,StorageDimensionGroup,TrackingDimensiongroup,modelGroupId,itemGroupId,unit,price,productCategory;
int64 productmasterrecid;
str 64PrdCategoryName,configid,colorid,sizeid,styleid,barcodeid,attributename,attributevalue,barcodesetupvalue,searchname,confignam,sizename,colorname,stylename;
inventItemBarCode inventItemBarCode;
// Product Master ends here
;
csvFile =
new CommaIO(filename,
'r');
try
{
if (csvFile)
{
ttsbegin;
while (csvFile.status() == IO_Status::OK)
{
readCon = csvFile.read();
icount++;
if(icount == 1)
continue;
itemId = conPeek(readCon,1); //(_conLine,#InventTable_ItemId_ColumnNum);
name = conPeek(readCon,2);
productDimensionGroup = conPeek(readCon,3);
StorageDimensionGroup = conPeek(readCon,4);
TrackingDimensiongroup = conPeek(readCon,5);
modelGroupId = conPeek(readCon,6);
itemGroupId = conPeek(readCon,7);
unit = conPeek(readCon,8);
price = conPeek(readCon,9);
productCategory = conPeek(readCon,10);
PrdCategoryName = conPeek(readCon,11);
configid = conPeek(readCon,12);
colorid = conPeek(readCon,13);
Sizeid = conPeek(readCon,14);
styleid = conPeek(readCon,15);
barcodeid = conPeek(readCon,16);
Barcodesetupvalue = conPeek(readCon,17);
Searchname = conPeek(readCon,18);
confignam = conPeek(readCon,19);
sizename = conPeek(readCon,20);
stylename = conPeek(readCon,21);
colorname = conPeek(readCon,22);
if(!itemId)
continue;
inventTable= InventTable::find(itemId);
//info(strFmt("%1 %2 %3 %4",configid,Sizeid,colorid,styleid));
if(inventTable)
this.Multilines(itemId,Sizeid,colorid,styleid,configid,searchname,barcodeid,unit,Barcodesetupvalue,name,confignam,sizename,stylename,colorname);
if(!inventTable)
{
if (readCon
&& icount > 1 )//dont insert first record of file : header
{
ecoResProductMaster.clear();
ecoResProductMaster.initValue();
ecoResProductMaster.ProductType = EcoResProductType::Item;
ecoResProductMaster.DisplayProductNumber = itemId;
ecoResProductMaster.SearchName = searchname;
ecoResProductMaster.VariantConfigurationTechnology =
EcoResVariantConfigurationTechnologyType::PredefinedVariants;
if (ecoResProductMaster.validateWrite())
{
ecoResProductMaster.insert();
ecoResProductIdentifier.clear();
ecoResProductIdentifier.initValue();
ecoResProductIdentifier.ProductNumber = itemId;
ecoResProductIdentifier.Product = ecoResProductMaster.RecId;
ecoResProductIdentifier.insert();
//Product dimension group
ecoResProductDimensionGroupProduct.clear();
ecoResProductDimensionGroupProduct.initValue();
ecoResProductDimensionGroupProduct.initFromProduct(ecoResProductMaster);
ecoResProductDimensionGroupProduct.ProductDimensionGroup =
EcoResProductDimensionGroup::findByDimensionGroupName(productDimensionGroup).RecId;
if (ecoResProductDimensionGroupProduct.validateWrite())
{
ecoResProductDimensionGroupProduct.insert();
}
//Storage dimension group
ecoResStorageDimensionGroupProduct.clear();
ecoResStorageDimensionGroupProduct.initValue();
ecoResStorageDimensionGroupProduct.Product = ecoResProductMaster.RecId;
ecoResStorageDimensionGroupProduct.StorageDimensionGroup =
EcoResStorageDimensionGroup::findByDimensionGroupName(StorageDimensionGroup).RecId;
if (ecoResStorageDimensionGroupProduct.validateWrite())
{
ecoResStorageDimensionGroupProduct.insert();
}
ecoResTrackingDimensionGroupProduct.clear();
ecoResTrackingDimensionGroupProduct.initValue();
ecoResTrackingDimensionGroupProduct.Product = ecoResProductMaster.RecId;
ecoResTrackingDimensionGroupProduct.TrackingDimensionGroup =
EcoResTrackingDimensionGroup::findByDimensionGroupName(TrackingDimensiongroup).RecId;
if (ecoResTrackingDimensionGroupProduct.validateWrite())
{
ecoResTrackingDimensionGroupProduct.insert();
}
//Product modeling policy
ecoResProductMasterModelingPolicy.clear();
ecoResProductMasterModelingPolicy.initValue();
ecoResProductMasterModelingPolicy.ProductMaster = ecoResProductMaster.RecId;
if (ecoResProductMasterModelingPolicy.validateWrite())
{
ecoResProductMasterModelingPolicy.insert();
}
//Product translation
EcoResProductTranslation::createOrUpdateTranslation(ecoResProductMaster.RecId,
name, name);
//Configuration
ecoResConfiguration = EcoResConfiguration::findByName(configid);
if (!ecoResConfiguration)
{
ecoResConfiguration.clear();
ecoResConfiguration.initValue();
ecoResConfiguration.Name = configid;
ecoResConfiguration.insert();
}
// Size
ecoResSize = ecoResSize::findByName(sizeid);
if (!ecoResSize)
{
ecoResSize.clear();
ecoResSize.initValue();
ecoResSize.Name = sizeid;
ecoResSize.insert();
}
// Style
ecoResStyle = ecoResStyle::findByName(styleid);
if (!ecoResStyle
&& styleid != "")
{
ecoResStyle.clear();
ecoResStyle.initValue();
ecoResStyle.Name = styleid;
ecoResStyle.insert();
}
// color
ecoResColor = ecoResColor::findByName(colorid);
if (!ecoResColor)
{
ecoResColor.clear();
ecoResColor.initValue();
ecoResColor.Name = colorid;
ecoResColor.insert();
}
//Configuration assigned to product master
ecoResProductMasterConfiguration.clear();
ecoResProductMasterConfiguration.initValue();
ecoResProductMasterConfiguration.Configuration = ecoResConfiguration.RecId;
ecoResProductMasterConfiguration.Description = confignam;
ecoResProductMasterConfiguration.ConfigProductDimensionAttribute =
EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, ConfigId));
ecoResProductMasterConfiguration.ConfigProductMaster =
ecoResProductMaster.RecId;
ecoResProductMasterConfiguration.insert();
//Sizes assigned to product master
ecoResProductMasterSize.clear();
ecoResProductMasterSize.initValue();
ecoResProductMasterSize.Size = ecoResSize.RecId;
ecoResProductMasterSize.Description = sizename;
ecoResProductMasterSize.SizeProductDimensionAttribute
= EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, InventSizeId));
ecoResProductMasterSize.SizeProductMaster = ecoResProductMaster.RecId;
ecoResProductMasterSize.insert();
//Style assigned to product master
ecoResProductMasterStyle.clear();
ecoResProductMasterStyle.initValue();
ecoResProductMasterStyle.Style
= ecoResStyle.RecId;//.RecId;
ecoResProductMasterStyle.Description = stylename;
ecoResProductMasterStyle.StyleProductDimensionAttribute
= EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, InventStyleId));
ecoResProductMasterStyle.StyleProductMaster = ecoResProductMaster.RecId;
ecoResProductMasterStyle.insert();
//Color assigned to product master
ecoResProductMasterColor.clear();
ecoResProductMasterColor.initValue();
ecoResProductMasterColor.Color
= ecoRescolor.RecId;//.RecId;
ecoResProductMasterColor.Description = colorname;
ecoResProductMasterColor.ColorProductDimensionAttribute
= EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, InventColorId));
ecoResProductMasterColor.ColorProductMaster = ecoResProductMaster.RecId;
ecoResProductMasterColor.insert();
//Product variant
ecoResDistinctProductVariant.clear();
ecoResDistinctProductVariant.initValue();
ecoResDistinctProductVariant.DisplayProductNumber =
EcoResProductNumberBuilderVariant::buildFromProductNumberAndDimensions(
ecoResProductMaster.productNumber(),
EcoResProductVariantDimValue::getDimensionValuesContainer(ecoResConfiguration.Name,
ecoResSize.Name, ecoResColor.Name,ecoResStyle.Name));
ecoResDistinctProductVariant.SearchName
= ecoResProductMaster.SearchName;// +
ItemId/*ConfigId*/;
ecoResDistinctProductVariant.ProductType = ecoResProductMaster.ProductType;
ecoResDistinctProductVariant.ProductMaster = ecoResProductMaster.RecId;
ecoResDistinctProductVariant.insert();
//Product variant configuration
ecoResProductVariantConfiguration.clear();
ecoResProductVariantConfiguration.initValue();
ecoResProductVariantConfiguration.initFromDistinctProductVariant(ecoResDistinctProductVariant);
ecoResProductVariantConfiguration.ProductDimensionAttribute
= EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, ConfigId));
ecoResProductVariantConfiguration.Configuration = ecoResConfiguration.RecId;
ecoResProductVariantConfiguration.insert();
//Size variant configuration
ecoResProductVariantSize.clear();
ecoResProductVariantSize.initValue();
ecoResProductVariantSize.initFromDistinctProductVariant(ecoResDistinctProductVariant);
ecoResProductVariantSize.ProductDimensionAttribute
= EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, InventSizeid));
ecoResProductVariantSize.Size = ecoResSize.RecId;
ecoResProductVariantSize.insert();
//Style variant configuration
ecoResProductVariantStyle.clear();
ecoResProductVariantStyle.initValue();
ecoResProductVariantStyle.initFromDistinctProductVariant(ecoResDistinctProductVariant);
ecoResProductVariantStyle.ProductDimensionAttribute
= EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, InventStyleid));
ecoResProductVariantStyle.Style = ecoResStyle.RecId;
ecoResProductVariantStyle.insert();
//Color variant configuration
ecoResProductVariantColor.clear();
ecoResProductVariantColor.initValue();
ecoResProductVariantColor.initFromDistinctProductVariant(ecoResDistinctProductVariant);
ecoResProductVariantColor.ProductDimensionAttribute
= EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, InventColorId));
ecoResProductVariantColor.Color = ecoResColor.RecId;
ecoResProductVariantColor.insert();
//Product variant translation
EcoResProductTranslation::createOrUpdateTranslation(ecoResDistinctProductVariant.RecId,
name, name);
//Released product
inventTable.clear();
inventTable.initValue();
inventTable.initFromEcoResProduct(ecoResProductMaster);
inventTable.ItemId = ItemId;
inventTable.NameAlias = searchname;
inventTable.CostModel = NoYes::Yes;
inventTable.PurchModel = NoYes::Yes;
if (inventTable.validateWrite())
{
inventTable.insert();
//Inventory model group
inventModelGroupItem.clear();
inventModelGroupItem.initValue();
inventModelGroupItem.ItemDataAreaId =
inventTable.dataAreaId;
inventModelGroupItem.ItemId =
inventTable.ItemId;
inventModelGroupItem.ModelGroupId =
modelGroupId;
inventModelGroupItem.ModelGroupDataAreaId
= curext();
inventModelGroupItem.insert();
//Item group
inventItemGroupItem.clear();
inventItemGroupItem.initValue();
inventItemGroupItem.ItemDataAreaId =
inventTable.dataAreaId;
inventItemGroupItem.ItemId =
inventTable.ItemId;
inventItemGroupItem.ItemGroupId =
itemGroupId;
inventItemGroupItem.ItemGroupDataAreaId
= curext();
inventItemGroupItem.insert();
//Extended product details - Inventory
inventTableModule.clear();
inventTableModule.initValue();
inventTableModule.ItemId =
inventTable.ItemId;
inventTableModule.ModuleType =
ModuleInventPurchSales::Invent;
inventTableModule.UnitId = unit;
inventTableModule.Price = any2real(price);
inventTableModule.insert();
//Extended product details - Purchase
inventTableModule.clear();
inventTableModule.initValue();
inventTableModule.ItemId =
inventTable.ItemId;
inventTableModule.ModuleType = ModuleInventPurchSales::Purch;
inventTableModule.UnitId = unit;
//inventTableModule.Price = any2real(price);
inventTableModule.insert();
//Extended product details - Sales
inventTableModule.clear();
inventTableModule.initValue();
inventTableModule.ItemId =
inventTable.ItemId;
inventTableModule.ModuleType =
ModuleInventPurchSales::Sales;
inventTableModule.Price = any2real(price);
inventTableModule.insert();
//Warehouse items
InventItemLocation::createDefault(inventTable.ItemId);
//Supply type setup
inventItemSetupSupplyType.clear();
inventItemSetupSupplyType.initValue();
inventItemSetupSupplyType.ItemId = inventTable.ItemId;
inventItemSetupSupplyType.ItemDataAreaId = inventTable.DataAreaId;
inventItemSetupSupplyType.insert();
//Product
storage dimension group
ecoResStorageDimensionGroupProduct =
EcoResStorageDimensionGroupProduct::findByProduct(ecoResProductMaster.RecId);
if (ecoResStorageDimensionGroupProduct.RecId)
{
ecoResStorageDimensionGroupItem.clear();
ecoResStorageDimensionGroupItem.initValue();
ecoResStorageDimensionGroupItem.ItemDataAreaId
= inventTable.DataAreaId;
ecoResStorageDimensionGroupItem.ItemId
= inventTable.ItemId;
ecoResStorageDimensionGroupItem.StorageDimensionGroup
= ecoResStorageDimensionGroupProduct.StorageDimensionGroup;
ecoResStorageDimensionGroupItem.insert();
}
//Product tracking dimension group
ecoResTrackingDimensionGroupProduct =
EcoResTrackingDimensionGroupProduct::findByProduct(ecoResProductMaster.RecId);
if (ecoResTrackingDimensionGroupProduct.RecId)
{
ecoResTrackingDimensionGroupItem.clear();
ecoResTrackingDimensionGroupItem.initValue();
ecoResTrackingDimensionGroupItem.ItemDataAreaId = inventTable.DataAreaId;
ecoResTrackingDimensionGroupItem.ItemId = inventTable.ItemId;
ecoResTrackingDimensionGroupItem.TrackingDimensionGroup =
ecoResTrackingDimensionGroupProduct.TrackingDimensionGroup;
ecoResTrackingDimensionGroupItem.insert();
}
//Product Category
EcoResProduct = EcoResProduct::findByDisplayProductNumber(itemid);
EcoResCategoryHierarchy =
EcoResCategoryHierarchy::findByName(PrdCategoryName);//"Procurement Hierarchy 1");//"Retail Product
Category");//"Procurement Hierarchy 1"); // category hierarchy
EcoResCategory = EcoResCategory::findByName(productCategory,EcoResCategoryHierarchy.RecId); //
category
EcoResProductCategory::insertEcoResProductCategory(EcoResCategory,EcoResProduct);
}
ecoResDistinctProductVariant
= ecoResDistinctProductVariant::find(ecoResDistinctProductVariant.RecId);//RecId);
//Now release the Product variant
releaseManager =
EcoResProductReleaseManagerBase::newFromProduct(ecoResDistinctProductVariant);
releaseManager.release();
select inventDim where inventDim.configId == configid
&& inventDim.InventSizeId == sizeid
&& inventDim.InventColorId == colorid
&& inventDim.InventStyleId == styleid;
inventDimCombination =
inventDimCombination::find(itemid,inventDim.inventDimId);
inventItemBarCode.itemId = itemid;
inventItemBarCode.barcodeSetupId
= "EAN128";
inventItemBarCode.inventDimId = inventDim.inventDimId;
inventItemBarCode.itemBarCode = barcodeid;
inventItemBarCode.RetailVariantId = inventDimCombination.RetailVariantId;
inventItemBarCode.useForInput = NoYes::Yes;
inventItemBarCode.useForPrinting = NoYes::Yes;
inventItemBarCode.UnitID = unit;
inventItemBarCode.insert();
inserted++;
}
}
}
}
ttsCommit;
}
icount--;//Remove
header recount from total record count
}
catch(Exception::Error)
{
info(strFmt("%1 %2",Exception::Error,icount));
}
}
private void Multilines(ItemId itemid,str 64 inventsize, str 64 inventcolor, str 64 inventstyle, str 64 config,str 64 name,str 64 Barcodeidd,str unit,str barcodesetuppvalue,str productname,str confignam,str sizename,str stylename,str colorname)
{
EcoResConfiguration
ecoResConfiguration;
EcoResSize ecoResSize;
EcoResStyle ecoResStyle;
EcoResColor ecoResColor;
EcoResProductMasterConfiguration ecoResProductMasterConfiguration;
EcoResProductMasterSize ecoResProductMasterSize;
EcoResProductMasterStyle ecoResProductMasterStyle;
EcoResProductMasterColor ecoResProductMasterColor;
EcoResDistinctProductVariant ecoResDistinctProductVariant;
EcoResProductVariantConfiguration ecoResProductVariantConfiguration;
EcoResProductVariantSize ecoResProductVariantSize;
EcoResProductVariantStyle ecoResProductVariantStyle;
EcoResProductVariantColor ecoResProductVariantColor;
ecoResProductMaster ecoResProductMaster;
InventTable inventtable;
InventDimCombination inventDimCombination;
InventDim inventDim;
InventItemBarcode inventItemBarCode;
;
select inventtable where inventtable.ItemId == itemid
join ecoResProductMaster where ecoResProductMaster.SearchName ==
name;
//Configuration
ecoResConfiguration = EcoResConfiguration::findByName(config);
if (!ecoResConfiguration)
{
ecoResConfiguration.clear();
ecoResConfiguration.initValue();
ecoResConfiguration.Name = config;
ecoResConfiguration.insert();
}
// Size
ecoResSize = ecoResSize::findByName(inventsize);
if (!ecoResSize)
{
ecoResSize.clear();
ecoResSize.initValue();
ecoResSize.Name = inventsize;
ecoResSize.insert();
}
// Style
ecoResStyle = ecoResStyle::findByName(inventstyle);
if (!ecoResStyle
&& inventstyle !="")
{
ecoResStyle.clear();
ecoResStyle.initValue();
ecoResStyle.Name = inventstyle;
ecoResStyle.insert();
}
// color
ecoResColor = ecoResColor::findByName(inventcolor);
if (!ecoResColor)
{
ecoResColor.clear();
ecoResColor.initValue();
ecoResColor.Name = inventcolor;
ecoResColor.insert();
}
//Configuration
assigned to product master
select ecoResProductMasterConfiguration where ecoResProductMasterConfiguration.Configuration
== ecoResConfiguration.RecId
&& ecoResProductMasterConfiguration.ConfigProductMaster ==
ecoResProductMaster.RecId;
if(!ecoResProductMasterConfiguration
&& config != "")
{
ecoResProductMasterConfiguration.clear();
ecoResProductMasterConfiguration.initValue();
ecoResProductMasterConfiguration.Configuration = ecoResConfiguration.RecId;
ecoResProductMasterConfiguration.Description = confignam;
ecoResProductMasterConfiguration.ConfigProductDimensionAttribute =
EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, ConfigId));
ecoResProductMasterConfiguration.ConfigProductMaster =
ecoResProductMaster.RecId;
ecoResProductMasterConfiguration.insert();
}
//Sizes assigned to product master
select ecoResProductMasterSize where ecoResProductMasterSize.Size ==
ecoResSize.RecId
&& ecoResProductMasterSize.SizeProductMaster ==
ecoResProductMaster.RecId;
if(!ecoResProductMasterSize
&& inventsize != "")
{
ecoResProductMasterSize.clear();
ecoResProductMasterSize.initValue();
ecoResProductMasterSize.Size = ecoResSize.RecId;
ecoResProductMasterSize.Description = sizename;
ecoResProductMasterSize.SizeProductDimensionAttribute =
EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, InventSizeId));
ecoResProductMasterSize.SizeProductMaster = ecoResProductMaster.RecId;
ecoResProductMasterSize.insert();
}
//Style
assigned to product master
select ecoResProductMasterStyle where ecoResProductMasterStyle.Style ==
ecoResStyle.RecId
&& ecoResProductMasterStyle.StyleProductMaster ==
ecoResProductMaster.RecId;
if(!ecoResProductMasterStyle
&& inventstyle != "")
{
ecoResProductMasterStyle.clear();
ecoResProductMasterStyle.initValue();
ecoResProductMasterStyle.Style = ecoResStyle.RecId;//.RecId;
ecoResProductMasterStyle.Description = stylename;
ecoResProductMasterStyle.StyleProductDimensionAttribute =
EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, InventStyleId));
ecoResProductMasterStyle.StyleProductMaster = ecoResProductMaster.RecId;
ecoResProductMasterStyle.insert();
}
//Color assigned to product master
select ecoResProductMasterColor where ecoResProductMasterColor.Color ==
ecoRescolor.RecId
&& ecoResProductMasterColor.ColorProductMaster ==
ecoResProductMaster.RecId ;
if(!ecoResProductMasterColor
&& inventcolor != "")
{
ecoResProductMasterColor.clear();
ecoResProductMasterColor.initValue();
ecoResProductMasterColor.Color = ecoRescolor.RecId;//.RecId;
ecoResProductMasterColor.Description = colorname;
ecoResProductMasterColor.ColorProductDimensionAttribute =
EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, InventColorId));
ecoResProductMasterColor.ColorProductMaster = ecoResProductMaster.RecId;
ecoResProductMasterColor.insert();
}
//Product variant
ecoResDistinctProductVariant.clear();
ecoResDistinctProductVariant.initValue();
ecoResDistinctProductVariant.DisplayProductNumber =
EcoResProductNumberBuilderVariant::buildFromProductNumberAndDimensions(
ecoResProductMaster.productNumber(),
EcoResProductVariantDimValue::getDimensionValuesContainer(ecoResConfiguration.Name,ecoResSize.Name,ecorescolor.Name,ecoresstyle.Name));
ecoResDistinctProductVariant.SearchName = ecoResProductMaster.SearchName;// +
ItemId/*ConfigId*/;
ecoResDistinctProductVariant.ProductType = ecoResProductMaster.ProductType;
ecoResDistinctProductVariant.ProductMaster = ecoResProductMaster.RecId;
ecoResDistinctProductVariant.insert();
//Product variant configuration
ecoResProductVariantConfiguration.clear();
ecoResProductVariantConfiguration.initValue();
ecoResProductVariantConfiguration.initFromDistinctProductVariant(ecoResDistinctProductVariant);
ecoResProductVariantConfiguration.ProductDimensionAttribute =
EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, ConfigId));
ecoResProductVariantConfiguration.Configuration = ecoResConfiguration.RecId;
ecoResProductVariantConfiguration.insert();
//Size variant configuration
ecoResProductVariantSize.clear();
ecoResProductVariantSize.initValue();
ecoResProductVariantSize.initFromDistinctProductVariant(ecoResDistinctProductVariant);
ecoResProductVariantSize.ProductDimensionAttribute =
EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, InventSizeid));
ecoResProductVariantSize.Size = ecoResSize.RecId;
ecoResProductVariantSize.insert();
//Style variant configuration
ecoResProductVariantStyle.clear();
ecoResProductVariantStyle.initValue();
ecoResProductVariantStyle.initFromDistinctProductVariant(ecoResDistinctProductVariant);
ecoResProductVariantStyle.ProductDimensionAttribute =
EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, InventStyleid));
ecoResProductVariantStyle.Style = ecoResStyle.RecId;
ecoResProductVariantStyle.insert();
//Color variant configuration
ecoResProductVariantColor.clear();
ecoResProductVariantColor.initValue();
ecoResProductVariantColor.initFromDistinctProductVariant(ecoResDistinctProductVariant);
ecoResProductVariantColor.ProductDimensionAttribute =
EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, InventColorId));
ecoResProductVariantColor.Color = ecoResColor.RecId;
ecoResProductVariantColor.insert();
//Product variant translation
EcoResProductTranslation::createOrUpdateTranslation(ecoResDistinctProductVariant.RecId,
productname, productname);
//Find newly created Product Variant
ecoResDistinctProductVariant =
ecoResDistinctProductVariant::find(ecoResDistinctProductVariant.RecId);//RecId);
//Now release the Product variant
releaseManager =
EcoResProductReleaseManagerBase::newFromProduct(ecoResDistinctProductVariant);
releaseManager.release();
select inventDim where inventDim.configId == config
&& inventDim.InventSizeId == inventsize
&& inventDim.InventColorId == inventcolor
&& inventDim.InventStyleId == inventstyle;
inventDimCombination = inventDimCombination::find(itemid,inventDim.inventDimId);
inventItemBarCode.itemId = itemid;
inventItemBarCode.barcodeSetupId = barcodesetuppvalue;//"EAN128";
inventItemBarCode.inventDimId = inventDim.inventDimId;
inventItemBarCode.itemBarCode = barcodeidd;
inventItemBarCode.RetailVariantId = inventDimCombination.RetailVariantId;
inventItemBarCode.useForInput = NoYes::Yes;
inventItemBarCode.useForPrinting = NoYes::Yes;
inventItemBarCode.UnitID = unit;
inventItemBarCode.insert();
}