Hi guys, Today we see how to Release product master from other product details in ax 2012 using X++.
Run the below job.
static void productMaterRelease(Args _args)
{
EcoResProductReleaseSessionManager ecoResProductReleaseSessionManager;
InventTable inventTable,inventTableLoc;
InventItemSetupSupplyType inventItemSetupSupplyType;
InventModelGroupItem inventModelGroupItem,inventModelGroupItemLoc;
RefRecId _productMasterRecId,_oldProductMasterRecId;
InventItemGroupItem inventItemGroupItem,inventItemGroupItemLoc;
WHSReservationHierarchyItem wHSReservationHierarchyItem,wHSReservationHierarchyItemLoc;
_productMasterRecId = 52565460661;
_oldProductMasterRecId = 22565432486;
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');
}
No comments:
Post a Comment