We can create product master using x++ code. I have used below code in one of my implementation.
private void createProductMaster(itemId _itemId,
DataAreaId _dataAreaId = curext()
)
{
EcoResProductService ecoResProdService;
EcoResEcoResProduct ecoResProduct;
EcoResEcoResProduct_Product_Master prodMaster;
EcoResEcoResProduct_Translation translation;
EcoResEcoResProduct_Identifier identifier;
EcoResEcoResProduct_ProductDimGroup prodDimGroup;
EcoResEcoResProduct_StorageDimGroup storageDimGroup;
EcoResEcoResProduct_TrackingDimGroup trackingDimensionGroup;
InventTable localInventTable;
;
if (!this.isProductAlreadyExists() && this.getItemId())
{
localInventTable = InventTable::find(_itemId);
//Initialize the service object
changeCompany(_dataAreaId)
{
ecoResProdService = EcoResProductService::construct();
ecoResProduct = new EcoResEcoResProduct();
prodMaster = new EcoResEcoResProduct_Product_Master();
//Newly created and initialize prodMaster
prodMaster.parmDisplayProductNumber(this.getItemId());
prodMaster.parmProductType(EcoResProductType::Item);
prodMaster.parmSearchName(this.getItemId());
//Create a new translation object:
Translation = prodMaster.createTranslation().addNew();
Translation.parmDescription(this.getItemLongDescription());
Translation.parmLanguageId(CompanyInfo::languageId());
Translation.parmName(this.getItemShortDescription());
Identifier = prodMaster.createIdentifier().addNew();
Identifier.parmProductNumber(this.getItemId());
if (localInventTable.productDimensionGroup())
{
ProdDimGroup = prodMaster.createProductDimGroup().addNew();
ProdDimGroup.parmProduct(this.getItemId());
ProdDimGroup.parmProductDimensionGroup(EcoResProductDimensionGroup::find(localInventTable.productDimensionGroup()).Name);
}
if (localInventTable.storageDimensionGroup())
{
if (EcoResStorageDimensionGroup::find(localInventTable.storageDimensionGroup()).Name)
{
storageDimGroup = prodMaster.createStorageDimGroup().addNew();
storageDimGroup.parmProduct(this.getItemId());
storageDimGroup.parmStorageDimensionGroup(EcoResStorageDimensionGroup::find(localInventTable.storageDimensionGroup()).Name);
}
}
if (localInventTable.trackingDimensionGroup())
{
if (EcoResTrackingDimensionGroup::find(localInventTable.trackingDimensionGroup()).Name)
{
trackingDimensionGroup = prodMaster.createTrackingDimGroup().addNew();
trackingDimensionGroup.parmProduct(this.getItemId());
trackingDimensionGroup.parmTrackingDimensionGroup(EcoResTrackingDimensionGroup::find(localInventTable.trackingDimensionGroup()).Name);
}
}
prodMaster.parmVariantConfigurationTechnology(EcoResVariantConfigurationTechnologyType::ConstraintBased);
ecoResProduct.createProduct().add(prodMaster);
ecoResProdService.create(ecoResProduct);
}
}
}
private void createProductMaster(itemId _itemId,
DataAreaId _dataAreaId = curext()
)
{
EcoResProductService ecoResProdService;
EcoResEcoResProduct ecoResProduct;
EcoResEcoResProduct_Product_Master prodMaster;
EcoResEcoResProduct_Translation translation;
EcoResEcoResProduct_Identifier identifier;
EcoResEcoResProduct_ProductDimGroup prodDimGroup;
EcoResEcoResProduct_StorageDimGroup storageDimGroup;
EcoResEcoResProduct_TrackingDimGroup trackingDimensionGroup;
InventTable localInventTable;
;
if (!this.isProductAlreadyExists() && this.getItemId())
{
localInventTable = InventTable::find(_itemId);
//Initialize the service object
changeCompany(_dataAreaId)
{
ecoResProdService = EcoResProductService::construct();
ecoResProduct = new EcoResEcoResProduct();
prodMaster = new EcoResEcoResProduct_Product_Master();
//Newly created and initialize prodMaster
prodMaster.parmDisplayProductNumber(this.getItemId());
prodMaster.parmProductType(EcoResProductType::Item);
prodMaster.parmSearchName(this.getItemId());
//Create a new translation object:
Translation = prodMaster.createTranslation().addNew();
Translation.parmDescription(this.getItemLongDescription());
Translation.parmLanguageId(CompanyInfo::languageId());
Translation.parmName(this.getItemShortDescription());
Identifier = prodMaster.createIdentifier().addNew();
Identifier.parmProductNumber(this.getItemId());
if (localInventTable.productDimensionGroup())
{
ProdDimGroup = prodMaster.createProductDimGroup().addNew();
ProdDimGroup.parmProduct(this.getItemId());
ProdDimGroup.parmProductDimensionGroup(EcoResProductDimensionGroup::find(localInventTable.productDimensionGroup()).Name);
}
if (localInventTable.storageDimensionGroup())
{
if (EcoResStorageDimensionGroup::find(localInventTable.storageDimensionGroup()).Name)
{
storageDimGroup = prodMaster.createStorageDimGroup().addNew();
storageDimGroup.parmProduct(this.getItemId());
storageDimGroup.parmStorageDimensionGroup(EcoResStorageDimensionGroup::find(localInventTable.storageDimensionGroup()).Name);
}
}
if (localInventTable.trackingDimensionGroup())
{
if (EcoResTrackingDimensionGroup::find(localInventTable.trackingDimensionGroup()).Name)
{
trackingDimensionGroup = prodMaster.createTrackingDimGroup().addNew();
trackingDimensionGroup.parmProduct(this.getItemId());
trackingDimensionGroup.parmTrackingDimensionGroup(EcoResTrackingDimensionGroup::find(localInventTable.trackingDimensionGroup()).Name);
}
}
prodMaster.parmVariantConfigurationTechnology(EcoResVariantConfigurationTechnologyType::ConstraintBased);
ecoResProduct.createProduct().add(prodMaster);
ecoResProdService.create(ecoResProduct);
}
}
}
No comments:
Post a Comment