Announcements
public ItemId releaseProduct(ItemId _itemId, ItemName _itemName, EcoResProductMaster _productMaster)
{
ItemId itemId;
InventTable inventTable;
InventItemSetupSupplyType inventItemSetupSupplyType;
EcoResStorageDimensionGroupProduct storageDimGroupProduct, productDimGroupProduct;
EcoResTrackingDimensionGroupProduct trackingDimGroupProduct;
EcoResStorageDimensionGroupItem storageDimensionGroupItem;
EcoResTrackingDimensionGroupItem trackingDimensionGroupItem;
inventTable.clear();
inventTable.initValue();
inventTable.initFromEcoResProduct(_productMaster);
inventTable.ItemId = _itemId;
inventTable.NameAlias = _itemName;
if (inventTable.validateWrite())
{
inventTable.insert();
}
InventItemLocation::createDefault(inventTable.ItemId);
inventItemSetupSupplyType.clear();
inventItemSetupSupplyType.initValue();
inventItemSetupSupplyType.ItemId = inventTable.ItemId;
inventItemSetupSupplyType.ItemDataAreaId = inventTable.DataAreaId;
inventItemSetupSupplyType.insert();
storageDimGroupProduct = EcoResStorageDimensionGroupProduct::findByProduct(_productMaster.RecId);
if (storageDimGroupProduct)
{
storageDimensionGroupItem.clear();
storageDimensionGroupItem.initValue();
storageDimensionGroupItem.ItemDataAreaId = inventTable.DataAreaId;
storageDimensionGroupItem.ItemId = inventTable.ItemId;
storageDimensionGroupItem.StorageDimensionGroup = storageDimGroupProduct.StorageDimensionGroup;
storageDimensionGroupItem.insert();
}
trackingDimGroupProduct = EcoResTrackingDimensionGroupProduct::findByProduct(_productMaster.RecId);
if (trackingDimGroupProduct)
{
trackingDimensionGroupItem.clear();
trackingDimensionGroupItem.initValue();
trackingDimensionGroupItem.ItemDataAreaId = inventTable.DataAreaId;
trackingDimensionGroupItem.ItemId = inventTable.ItemId;
trackingDimensionGroupItem.TrackingDimensionGroup = trackingDimGroupProduct.TrackingDimensionGroup;
trackingDimensionGroupItem.insert();
}
itemId = inventTable.ItemId;
return itemId;
}
MyMethod()
{
void createUpdateInventItem(InventItemOrderSetupMap _inventItemTable, InventDimId _inventDimId, InventDimId _defaultInventDimId)
{
if (_inventItemTable)
{
_inventItemTable.InventDimIdDefault = _defaultInventDimId;
_inventItemTable.update();
}
else
{
_inventItemTable.clear();
_inventItemTable.ItemId = itemId;
_inventItemTable.InventDimId = _inventDimId;
_inventItemTable.InventDimIdDefault = _defaultInventDimId;
_inventItemTable.insert();
}
}
companyParameters = CustomCompanyParameters::find();
inventDimAllBlank = InventDim::findOrCreateBlank();
inventDimSite.clear();
inventDimSite.initValue();
inventDimSite.InventSiteId = companyParameters.DefaultInventSiteId;
inventDimSite = InventDim::findOrCreate(inventDimSite);
inventDimLocation.clear();
inventDimLocation.initValue();
inventDimLocation.InventLocationId = companyParameters.DefaultInventLocationId;
inventDimLocation = InventDim::findOrCreate(inventDimLocation);
// Invent setup
inventItemInventSetup = InventItemInventSetup::findDefault(itemId, true);
createUpdateInventItem(inventItemInventSetup, inventDimAllBlank.inventDimId, inventDimSite.inventDimId);
inventItemInventSetup.clear();
select firstOnly inventItemInventSetup
where inventItemInventSetup.ItemId == itemId
&& inventItemInventSetup.InventDimId == inventDimSite.inventDimId;
createUpdateInventItem(inventItemInventSetup, inventDimSite.inventDimId, inventDimLocation.inventDimId);
// Purchase setup
inventItemPurchSetup = InventItemPurchSetup::find(itemId, inventDimAllBlank.inventDimId, true);
createUpdateInventItem(inventItemPurchSetup, inventDimAllBlank.inventDimId, inventDimSite.inventDimId);
inventItemPurchSetup.clear();
select firstOnly inventItemPurchSetup
where inventItemPurchSetup.ItemId == itemId
&& inventItemPurchSetup.InventDimId == inventDimSite.inventDimId;
createUpdateInventItem(inventItemPurchSetup, inventDimSite.inventDimId, inventDimLocation.inventDimId);
// Sales setup
inventItemSalesSetup = InventItemSalesSetup::find(itemId, inventDimAllBlank.inventDimId, true);
createUpdateInventItem(inventItemSalesSetup, inventDimAllBlank.inventDimId, inventDimSite.inventDimId);
inventItemSalesSetup.clear();
select firstOnly inventItemSalesSetup
where inventItemSalesSetup.ItemId == itemId
&& inventItemSalesSetup.InventDimId == inventDimSite.inventDimId;
createUpdateInventItem(inventItemSalesSetup, inventDimSite.inventDimId, inventDimLocation.inventDimId);
​​​​​​​
}
I completely agree with your perspective. The bugs, overly complex logic, and general maintenance challenges are exactly why I’d like to rebuild this operation instead of simply porting the code from AX to D365 as it is (I wasn’t the original developer for this).
From the examples I found online (like the ones I linked), it seems that much of the custom code I shared - such as item parameters, item groups, units, and dimension groups - can be managed through EcoResReleasedProductCreationV2Entity.
However, although I didn’t include code for the remaining methods I mentioned (I can share it if needed), would I still be able to configure the default dimension, purchase/sales parameters, and item serial numbers through it? Or should I consider other EcoResProduct entities as well?
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,734 Super User 2024 Season 2
Martin Dráb 229,021 Most Valuable Professional
nmaenpaa 101,150