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)); 

 

Comments

Popular posts from this blog

Channel Setup Part 2 ---- Create Organizational Hierarchy in D365 F&O

How to Create Extended Data Types (EDTs) in Finance and Operations of Dynamics 365 -- F&O Customization Part 2

Batch Job stuck in "Waiting" state in D365 F&O?