Retrieve default inventory dimensions for an item x++
X++
code to retrieve default inventory dimensions for an item in Dynamics 365
Finance and Operations.
InventTable inventTable = InventTable::find('D0004');
InventItemOrderSetupType setupType = InventItemOrderSetupType::Invent;
InventDim inventDim;
// Default Site
inventDim.InventSiteId = inventTable.inventItemOrderSetupMap(setupType).inventSiteId(inventDim.InventSiteId, inventTable);
// Default Location
inventDim.InventLocationId = inventTable.inventItemOrderSetupMap(setupType, inventDim.InventDimId).inventLocationId(inventDim.InventLocationId, inventTable, inventDim.InventSiteId);
// Default ConfigId
inventDim.ConfigId = inventTable.StandardConfigId;
// Find or create default item dimension
inventDim = InventDim::findOrCreate(inventDim);
info(strFmt('Invent Dim. Id: %1', inventDim.inventDimId));
info(strFmt('Site Id: %1', inventDim.InventSiteId));
info(strFmt('Location Id: %1', inventDim.InventLocationId));
InventTable inventTable = InventTable::find('D0004');
InventItemOrderSetupType setupType = InventItemOrderSetupType::Invent;
InventDim inventDim;
// Default Site
inventDim.InventSiteId = inventTable.inventItemOrderSetupMap(setupType).inventSiteId(inventDim.InventSiteId, inventTable);
// Default Location
inventDim.InventLocationId = inventTable.inventItemOrderSetupMap(setupType, inventDim.InventDimId).inventLocationId(inventDim.InventLocationId, inventTable, inventDim.InventSiteId);
// Default ConfigId
inventDim.ConfigId = inventTable.StandardConfigId;
// Find or create default item dimension
inventDim = InventDim::findOrCreate(inventDim);
info(strFmt('Invent Dim. Id: %1', inventDim.inventDimId));
info(strFmt('Site Id: %1', inventDim.InventSiteId));
info(strFmt('Location Id: %1', inventDim.InventLocationId));
Comments