
Hi,
I'm trying to create production order through code but it giving an error of "Inventory dimension Site is mandatory and must consequently be specified." even I've set the site and location.
Below is the code
ProdTable prodtable;
InventTable inventTable;
InventDim inventDim,inventDimlocal;
InventItemOrderSetupType setupType = InventItemOrderSetupType::Invent;
;
inventTable = inventTable::find(_selectedLines.ItemNumber);
prodtable.initValue();
prodtable.initFromInventTable(inventTable);
prodtable.ItemId = inventTable.ItemId;
prodtable.DlvDate = _selectedLines.RequestDate;
prodtable.QtySched = _selectedLines.Quantity;
prodtable.RemainInventPhysical = _selectedLines.Quantity;
inventDim.initValue();
inventDim.InventSiteId = '1';
// Default Location
inventDim.InventLocationId = '11';
inventDim.ConfigId = inventTable.StandardConfigId;
inventDimlocal = InventDim::findOrCreate(inventDim);
prodtable.BOMId = BOMVersion::findActive(prodtable.ItemId,
prodtable.BOMDate,
prodtable.QtySched,
inventDimlocal).BOMId;
prodtable.RouteId = RouteVersion::findActive(prodtable.ItemId,
prodtable.BOMDate,
prodtable.QtySched,
inventDimlocal).RouteId;
prodtable.initBOMVersion();
prodtable.initRouteVersion();
ttsbegin;
prodtable.insert();
ttscommit;
A good general approach to such errors is to look at the production orders that are created via D365 UI, using table browser or SQL Server Management Studio. This way you will see what good data looks like.
Then try to write code that creates similar data.
Seems that you don't set ProdTable.InventDimId in your code. Perhaps that causes the error.