Tuesday, November 6, 2012

AX 2012 Find On Hand (Physical) Inventory By Date

Below is a quick way to return the On Hand (Physical) Inventory for an item and dimension value combination (variant and location in AX Retail term). Note that this is for on hand inventory, not ATP or anything. This method assumes that you are passing an item, an inventory dimension record, and a date.

Parameters:
  • _itemId - The Item Id for the item
  • _inventDim - The inventory dimension record for the item (variant)
  • _date - The date that we want to see the on hand inventory amount for

private Qty findOnHandByDate(ItemId _itemId, InventDim _inventDim, Date _date)
{
    InventDimParm    inventDimParmCrit;
    InventSumDateDim inventSumDateDim;
    ;

    // Set the dimensions
    inventDimParmCrit.initFromInventDim(_inventDim);
    inventSumDateDim = inventSumDateDim::newParameters(_date, _itemId, _inventDim, inventDimParmCrit);

    return InventSumDateDim.postedQty();
}

5 comments:

  1. Hi

    Thanks for posting this. Just a quick question. If you do not specify any inventory dimensions, will it return on hand values for all dimensions (locations)?

    Kind regards
    Stephen

    ReplyDelete
    Replies
    1. Stephen,

      The fast answer to your question is yes. If you use the record which has an inventDimId of 'AllBlank', then it will let you know the physical inventory qty for your entire legal entity (across all warehouses).
      Here is a quick job using the code above to find legal entity wide inventory for Item 'A0001'.

      static void Job5(Args _args)
      {
      InventDimParm inventDimParmCrit;
      InventSumDateDim inventSumDateDim;
      InventDim inventDim = InventDim::find('AllBlank');
      ;

      // Set the dimensions
      inventDimParmCrit.initFromInventDim(inventDim);
      inventSumDateDim = inventSumDateDim::newParameters(today(), 'A0001', inventDim, inventDimParmCrit);

      info(strFmt("%1", InventSumDateDim.av()));
      }

      Delete
  2. .av() is not even there in this class.

    ReplyDelete
    Replies
    1. .av() from the comment was a typo. I am not able to edit the comments.

      Following the code example in the post and looking contextually at the comment that contains the typo, you can infer that the .av() should be .postedQty() like in the example from the blog post.

      Are you confused or have a specific question?

      Delete
  3. Hi Justin,

    How do i get the Physical reserved or Available Physical for the past dates? The above method helps me to get the Physical Available and thanks for that

    ReplyDelete