To find stock On-Hand in AX through X++


static void findOnHand(Args _args)
{
 
InventDim inventDim;
InventDimParm inventDimParm;
Itemid itemid;
InventOnHand inventOnHand = new InventOnHand();
;

// take a sample item for testing
itemid = "Item1";

// take a combination of dimension , against which you want to find the stock
inventDim.InventLocationId = "HYD";

//Set the flag for the selected dimensions as active.
inventDimParm.initFromInventDim(inventDim);

//initialize the inventonhand with item,dimension and dim paramter

inventOnHand.parmItemId(itemid);
inventOnHand.parmInventDim(inventDim);
inventOnHand.parmInventDimParm(inventDimParm);

// Retrieve the onhand info
info(strfmt("Available Physical: %1",
inventOnhand.availPhysical()));
info(strfmt("On order: %1",inventOnhand.onOrder()));

}



To find out stock in inventsum using code X++:

static void ItemOnhandSum(Args _args)
{
    InventSum           inventsum;
    Qty                 availableQty = 0;
    ;

    select sum(PostedQty),
        sum(Received),
        sum(Deducted),
        sum(Registered),
        sum(Picked),
        sum(ReservPhysical),
        sum(Ordered),
        sum(Arrived),
        sum(ReservOrdered),
        sum(OnOrder) from inventsum
        where inventsum.ItemId      == "KCYIWU001";
    if (inventsum)
    {
        availableQty = inventsum.PostedQty
            + inventsum.Received
            - inventsum.Deducted
            + inventsum.Registered
            - inventSum.Picked
            - inventSum.ReservPhysical
            + inventsum.Ordered
            + inventsum.Arrived
            - inventsum.ReservOrdered
            - inventsum.OnOrder;
    }
    info(strfmt('%1', availableQty));
}



To find on- hand Stock by date :

static void findOnHand_ByDate(Args _args)
{
InventDim inventDim;
InventDimParm inventDimParm;
Itemid itemid;
InventOnHand inventOnHand = new InventOnHand();
InventSumDateDim inventSumDateDim;
TransDate transDate;
;

// take a sample item for testing
itemid = "20 MM RMC";
transDate = 13\01\2010;

// take a combination of dimension , against which you want to find the stock
inventDim.InventLocationId = "GW";

//Set the flag for the selected dimensions as active.
inventDimParm.initFromInventDim(inventDim);

//initialize the inventSumDateDim with Date,item,dimension and dim paramter

inventSumDateDim = InventSumDateDim::newParameters(transDate,
itemid,
inventDim,
inventDimParm);


// Retrieve the onhand info
info(strfmt("PostedQty: %1",inventSumDateDim.postedQty()));
info(strfmt("DeductedQty: %1",inventSumDateDim.deductedQty()));
info(strfmt("ReceivedQty: %1",inventSumDateDim.receivedQty()));

}


10 comments:

  1. Hi Vishal,
    How can i retrieve reserved qty??? I have checked the inventsumdatedim class but it doesnt have a reserved() method..
    Please guide me on this

    ReplyDelete
  2. Hi Vishal,

    I want to trigger an event on change in On hand Stock physical available, What is the right place to put the code for it?

    ReplyDelete
  3. Even I need to trigger an event on change in On hand Stock physical available? any suggestions????

    ReplyDelete
    Replies
    1. You can use the standard functionality for Alerts (https://technet.microsoft.com/en-us/library/aa499769.aspx). (Or) You can write a piece of code that will compare the current on hand stock with the previous one(Insert/Update).

      Delete
  4. Excellent article, thanks!

    ReplyDelete
  5. Thank you... you help me so much! :)

    ReplyDelete
    Replies
    1. Your welcome! Keep visiting for more interesting articles :)

      Delete

Agentic AI - This Isn't the Next Wave. This Is the New Ground.

  Let me say something that might make some people uncomfortable. Most organizations are still debating whether to adopt AI. Meanwhile, t...

Powered by Blogger.