Hi guys, Today we see how to create Product master, Product dimensions, variants, Product master release, Release Product variants, External product in Ax 2012 using X++.
All operations done in this post.
If you want separate check other posts.
static void productMaster(Args _args)
{
EcoResProductMaster ecoResProductMaster;
EcoResProductDimensionGroupProduct ecoResProductDimensionGroupProduct;
EcoResStorageDimensionGroupItem ecoResStorageDimensionGroupItem;
EcoResTrackingDimensionGroupItem ecoResTrackingDimensionGroupItem;
EcoResProductMasterManager productMasterManager;
EcoResProductTranslation ecoResProductTranslation;
EcoResConfiguration ecoResConfiguration;
EcoResProductMasterConfiguration productMasterConfiguration;
EcoResDistinctProductVariant ecoResDistinctProductVariant;
InventDim inventDim;
InventDimCombination inventDimCombination;
custVendExternalItem custVendExternalItem,custVendExternalItemLoc;
EcoResProductReleaseSessionManager ecoResProductReleaseSessionManager;
InventTable inventTable,inventTableLoc;
InventItemSetupSupplyType inventItemSetupSupplyType;
InventModelGroupItem inventModelGroupItem,inventModelGroupItemLoc;
InventItemGroupItem inventItemGroupItem,inventItemGroupItemLoc;
WHSReservationHierarchyItem wHSReservationHierarchyItem,wHSReservationHierarchyItemLoc;
RefRecId _productMasterRecId,_oldproductMasterRecId;
Name id,_name="DX";
container con,dimensionValues;
int i=1;
_oldproductMasterRecId = 22565432486;
// Product master creation
ecoResProductMaster = EcoResProductMaster::find(_oldproductMasterRecId);
if (ecoResProductMaster)
{
inventTable = InventTable::findByProduct(ecoResProductMaster.RecId);
ecoResProductDimensionGroupProduct = EcoResProductDimensionGroupProduct::findByProduct(ecoResProductMaster.RecId);
ecoResStorageDimensionGroupItem = EcoResStorageDimensionGroupItem::findByItem(inventTable.dataAreaId,inventTable.ItemId);
ecoResTrackingDimensionGroupItem = EcoResTrackingDimensionGroupItem::findByItem(inventTable.dataAreaId,inventTable.ItemId);
productMasterManager = EcoResProductMasterManager::construct();
_productMasterRecId = productMasterManager.createProductMaster(
_name + ecoResProductMaster.DisplayProductNumber,
ecoResProductMaster.SearchName,
ecoResProductMaster.ProductType,
ecoResProductMaster.VariantConfigurationTechnology,
ecoResProductDimensionGroupProduct.ProductDimensionGroup,
ecoResStorageDimensionGroupItem.StorageDimensionGroup,
ecoResTrackingDimensionGroupItem.TrackingDimensionGroup);
select firstOnly Name, Description from ecoResProductTranslation
where ecoResProductTranslation.Product == ecoResProductMaster.RecId;
EcoResProductTranslation::createOrUpdateTranslation(_productMasterRecId, ecoResProductTranslation.Name, ecoResProductTranslation.Description);
}
info(strFmt('%1',EcoResProductMaster::find(_productMasterRecId).DisplayProductNumber));
// create variants
con = ['1004','1005','1006'];
ecoresproductmaster = ecoresproductmaster::find(_productmasterrecid);
if (ecoresproductmaster)
{
for (i=1 ; i<=conlen(con) ; i++)
{
ecoresconfiguration = ecoresconfiguration::findbyname(conpeek(con, i));
if (!ecoresconfiguration)
{
ecoresconfiguration.clear();
ecoresconfiguration.initvalue();
ecoresconfiguration.name = conpeek(con,i);
ecoresconfiguration.insert();
}
select firstonly recid from inventdim
where inventdim.configid == ecoresconfiguration.name;
if (!inventdim.recid)
{
inventdim.clear();
inventdim.configid = ecoresconfiguration.name;
inventdim = inventdim::create(inventdim);
}
productmasterconfiguration = ecoresproductmasterconfiguration::find(ecoresproductmaster.recid,ecoresconfiguration.recid);
if (!productmasterconfiguration)
{
productmasterconfiguration.clear();
productmasterconfiguration.initvalue();
productmasterconfiguration.configproductmaster = ecoresproductmaster.recid;
productmasterconfiguration.configuration = ecoresconfiguration.recid;
productmasterconfiguration.configproductdimensionattribute = ecoresproductdimensionattribute::inventdimfieldid2dimensionattributerecid(fieldnum(inventdim, configid));
productmasterconfiguration.insert();
}
dimensionvalues = ecoresproductvariantdimvalue::getdimensionvaluescontainer(ecoresconfiguration.name);
ecoresdistinctproductvariant = ecoresproductvariantmanager::finddistinctproductvariant(ecoresproductmaster.recid,dimensionvalues);
if (!ecoresdistinctproductvariant)
{
ecoresproductvariantmanager::createproductvariant(ecoresproductmaster.recid,
ecoresproduct::find(ecoresproductmaster.recid).searchname + ecoresconfiguration.name,
dimensionvalues);
}
}
}
//release product master
ecoResProductReleaseSessionManager = EcoResProductReleaseSessionManager::newReleaseSession();
ecoResProductReleaseSessionManager.addProductMasterWithVariants(_productMasterRecId);
ecoResProductReleaseSessionManager.addLegalEntityForAllProducts(CompanyInfo::findDataArea(curext()).RecId);
if(ecoResProductReleaseSessionManager.execute())
{
inventTable = InventTable::findByProduct(_productMasterRecId,true);
inventTableLoc = InventTable::findByProduct(_oldProductMasterRecId,true);
if (inventTable)
{
ttsBegin;
inventItemSetupSupplyType = InventItemSetupSupplyType::find(inventTable.ItemId,curext(),true);
if (inventItemSetupSupplyType)
{
inventItemSetupSupplyType.DefaultOrderType = ReqPOType::Production;
inventItemSetupSupplyType.update();
}
ttsCommit;
inventModelGroupItemLoc = InventModelGroupItem::findByItemIdLegalEntity(inventTableLoc.ItemId,curext());
inventModelGroupItem.clear();
inventModelGroupItem.initValue();
inventModelGroupItem.ItemDataAreaId = inventTable.dataAreaId;
inventModelGroupItem.ItemId = inventTable.ItemId;
inventModelGroupItem.ModelGroupId = inventModelGroupItemLoc.ModelGroupId;
inventModelGroupItem.ModelGroupDataAreaId = curext();
inventModelGroupItem.insert();
inventItemGroupItemLoc = InventItemGroupItem::findByItemIdLegalEntity(inventTableLoc.ItemId,curext());
inventItemGroupItem.clear();
inventItemGroupItem.initValue();
inventItemGroupItem.ItemDataAreaId = inventTable.dataAreaId;
inventItemGroupItem.ItemId = inventTable.ItemId;
inventItemGroupItem.ItemGroupId = inventItemGroupItemLoc.ItemGroupId;
inventItemGroupItem.ItemGroupDataAreaId = curext();
inventItemGroupItem.insert();
wHSReservationHierarchyItemLoc = WHSReservationHierarchyItem::findByItem(curext(),inventTableLoc.ItemId);
wHSReservationHierarchyItem.clear();
wHSReservationHierarchyItem.initValue();
wHSReservationHierarchyItem.ReservationHierarchy = wHSReservationHierarchyItemLoc.ReservationHierarchy;
wHSReservationHierarchyItem.ItemId = inventTable.ItemId;
wHSReservationHierarchyItem.ItemDataAreaId = inventTable.dataAreaId;
wHSReservationHierarchyItem.insert();
}
info('Product released');
}
//External product creation
inventTable = InventTable::findByProduct(_productMasterRecId);
select firstOnly InventDimId, ItemId from inventDimCombination
where inventDimCombination.ItemId == inventTable.ItemId;
inventDim = InventDim::find(inventDimCombination.InventDimId);
select firstOnly custVendExternalItemLoc
where custVendExternalItemLoc.ItemId == inventTable.ItemId;
custVendExternalItem.clear();
custVendExternalItem.initValue();
custVendExternalItem.ItemId = inventDimCombination.ItemId;
custVendExternalItem.ExternalItemId = inventTable.ItemId;
custVendExternalItem.ModuleType = ModuleInventPurchSalesVendCustGroup::CustGroup;
custVendExternalItem.CustVendRelation = '01';
custVendExternalItem.ExternalItemTxt = inventTable.itemName();
custVendExternalItem.Description = inventTable.itemName();
custVendExternalItem.InventDimId = inventDim.inventDimId;
custVendExternalItem.insert();
info('externalProuct created');
// release variants to released product
//EcoResProductReleaseManagerBase releaseManager;
//EcoResProductMaster ecoResProductMaster;
//EcoResDistinctProductVariant ecoResDistinctProductVariant;
//Name configId;
//container con,dimensionvalues;
//int i=1;
//RefRecId _productMasterRecId;
//
//con = ['1004','1005','1006'];
//_productMasterRecId = 52565460661;
//ecoResProductMaster = EcoResProductMaster::find(_productMasterRecId);
//for (i=1 ; i<=conLen(con) ; i++)
//{
//configId = conPeek(con,i);
//
//select firstOnly ecoResDistinctProductVariant
//where ecoResDistinctProductVariant.ProductMaster == ecoResProductMaster.RecId
//&& ecoResDistinctProductVariant.DisplayProductNumber == EcoResProductNumberBuilderVariant::buildFromProductNumberAndDimensions(ecoResProductMaster.productNumber(),
//EcoResProductVariantDimValue::getDimensionValuesContainer(configId));
//if (ecoResDistinctProductVariant && !ecoResDistinctProductVariant.isReleased())
//{
//releaseManager = EcoResProductReleaseManagerBase::newFromProduct(ecoResDistinctProductVariant);
//releaseManager.release();
//}
//}
//info('Product variants released');
}
Keep Daxing!!
No comments:
Post a Comment