One thing that you will have to learn sooner rather than later is how the inventory dimensions work. Basically, the InventDim
table holds information about all the different dimensions that are related to an item. These dimensions can be divided into three types: item, storage, and tracking dimensions. By default, AX comes with the following dimensions:
When combinations of these dimensions are needed in a journal or a transaction, we always check to see whether the combination already exists. If it does, we link to that record in the InventDim
table. If it doesn't exist, a new record is created in the InventDim
table with the different dimensions filled out. Then, we can link to the new record. This is done by using a method called findOrCreate
from the InventDim
table. You can see how to use it in the following code:
static void findingDimension(Args _args), { InventDim inventDim; // Set the values that you need for // the journal or transaction inventDim.InventLocationId = "01"; inventDim.InventColorId = "02"; // Use findOrCreate and use the inventDim // variable that you have set values into inventDim = InventDim::findOrCreate(inventDim); // Use the inventDimId to link to the // InventDim record that was either // found or created info(inventDim.inventDimId); }
Another thing you should know is how to find how many items are available within a certain InventDim
scope. You can do this by converting the InventDim
fields into an InventDim
variable and then specifying which dimension fields or combination of dimension fields you would like to get on-hand information on. In the following example, we search for the on-hand information for an item in a specific color:
static void findingOnHandInfo(Args _args) { ItemId itemId; InventDim inventDimCriteria; InventDimParm inventDimParm; InventOnhand inventOnhand; // Specify the item to get onhand info on itemId = "1001"; // initilise inventOnHand inventOnhand = InventOnhand::newItemId(itemId); // Specify the dimensions you want // to filter the onhand info on inventDimCriteria.InventColorId = "02"; // Set the parameter flags active // according to which of the dimensions // in inventDimCriteria that are set inventDimParm.initFromInventDim(inventDimCriteria); // Specify the inventDim, // inventDimParm and itemId inventOnhand.parmInventDim(inventDimCriteria); inventOnhand.parmInventDimParm(inventDimParm); inventOnhand.parmItemId(itemId); // Retrieve the onhand info info(strfmt("Available Physical: %1",inventOnhand.availPhysical())); info(strfmt("On order: %1",inventOnhand.onOrder())); }
You could easily narrow the information down to a specific warehouse by setting a warehouse (InventLocationId
) to the inventDimCriteria
method, as we have done for the InventColorId
value.
The following example will let you find the on-hand quantity information of a specific item with a specific color (inventory dimension) at a specific date. The code is as follows:
static void findingOnHandByDate(Args _args) { ItemId itemId; InventDim inventDimCriteria; InventDimParm inventDimParm; InventSumDateDim inventSumDateDim; // Specify the item to get onhand info on itemId = "1001"; // Specify the dimensions you want // to filter the onhand info on inventDimCriteria.InventColorId = "02"; // Set the parameter flags active // accoring to which of the dimensions // in inventDimCriteria that are set inventDimParm.initFromInventDim(inventDimCriteria); // Specify the transaction date, inventDimCriteria, // inventDimParm and itemId to receive a new object // of InventSumDateDim inventSumDateDim = InventSumDateDim::newParameters(mkdate(01,01,2014),itemId, inventDimCriteria, inventDimParm); // Retrieve the on hand info using the methods // of InventSumDateDim info(strfmt("PostedQty: %1",inventSumDateDim.postedQty())); info(strfmt("DeductedQty: %1",inventSumDateDim.deductedQty())); info(strfmt("ReceivedQty: %1",inventSumDateDim.receivedQty())); }
One of the things you will need to know when dealing with the inventory module is how to automate journal entry and posting. This example will show you one way of doing this. This method is typically used when performing data migration. The code is as follows:
static void enterPostInventJournal(Args _args) { InventJournalName inventJournalName; InventJournalTable inventJournalTable; InventJournalTrans inventJournalTrans; InventJournalTableData inventJournalTableData; InventJournalTransData inventJournalTransData; InventTable inventTable; InventDim inventDim; select firstonly inventTable; // find item // find a movement journal name select firstOnly inventJournalNamewhere inventJournalName.JournalType == InventJournalType::Movement; // Initialize the values in the inventJournalTable // from the inventJournalName and insert the record inventJournalTable.clear(); inventJournalTable.initValue(); inventJournalTable.initFromInventJournalName(inventJournalName); inventJournalTable.insert(); inventJournalTableData = JournalTableData::newTable(inventJournalTable); // Insert to records into the inventJournalTrans table inventJournalTrans.clear(); inventJournalTrans.initFromInventJournalTable(inventJournalTable); inventJournalTrans.TransDate = systemdateget(); inventJournalTrans.initFromInventTable(inventTable); inventJournalTrans.Qty = 3; // Find the default dimension inventDim.initFromInventTable(inventJournalTrans.inventMovement().inventTable(),InventItemOrderSetupType::Invent,inventDim); // Set additional mandatory dimensions - based on item selected //inventDim.InventColorId = "02"; //inventDim.InventSizeId = "50"; //inventDim.configId = "HD"; // See if the inventDim with the selected values // allready exist in the InventDim table. If not, it's // created automatically inventDim = InventDim::findOrCreate(inventDim); inventJournalTrans.InventDimId = inventDim.inventDimId; inventJournalTransData = inventJournalTableData.journalStatic().newJournalTransData(inventJournalTrans,inventJournalTableData); inventJournalTransData.create(); // Use the InventJournalCheckPost class to // post the journal if (InventJournalCheckPost::newPostJournal(inventJournalTable).validate()) InventJournalCheckPost::newPostJournal (inventJournalTable).run(); }
3.16.69.143