Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

Wrong on hand value for WHS enabled item. X++ Ax2012 R3

(0) ShareShare
ReportReport
Posted on by 3,248

Hi

I am using below piece of code to calculate on hand for an item.  Generally it works fine, however for the items that are used in the WHS processes the value returned is wrong. Basically inventOnHand.availPhysical() method fails, i have added the code form std Ax , for the "AvailPhysical method looks like it not returning  correct values. Does anyone encountered it before?


public InventQtyAvailPhysical A_onHand()
{
    InventDim   inventDim;
    InventOnHand    inventOnhand;
    InventDimParm  InventDimParm;
    ;

    InventDimParm.initFromInventDim(inventDim);
    inventOnhand = inventOnhand::newParameters(this.ItemId, inventDim, InventDimParm);
    return inventOnhand.availPhysical();
}

STD AX code:

/// <summary>
/// Gets the the quantity available for physical reservation.
/// </summary>
/// <returns>
/// The quantity in the inventory unit.
/// </returns>
public InventQtyAvailPhysical availPhysical()
{
    // Don't do math for this quantity, instead use the value in InventSum
    // because it's the correct number for WHS Items
    if (itemUsesWHS)
    {
        this.setInventSum();
        this.setAvailability();

        return inventSum.AvailPhysical;
    }
    else
    {
        return (this.physicalInvent() - this.reservPhysical());
    }
}

Thanks

P

*This post is locked for comments

  • Suggested answer
    fatihgork Profile Picture
    fatihgork 3,815 on at
    RE: Wrong on hand value for WHS enabled item. X++ Ax2012 R3

    Hi,

    We have encountered the same issue. The main thing is considering Physical On Hand form's attidute in Warehouse Management module as reference.

    I'm not a developer, so I can't provide you the code but, we develop our codes to show On-hand based on WhsInventReserve table.

    I hope that information helps.

  • Suggested answer
    Faqruddin Profile Picture
    Faqruddin 1,875 on at
    RE: Wrong on hand value for WHS enabled item. X++ Ax2012 R3

    Hello Pradeep,

    The below code will works for you. It returns Available physical items from Warehouse.

    static void Job3(Args _args)
    {

    InventOnhand inventOnhand;

    InventDim inventDim;

    InventDimParm inventDimParm;

    ItemId itemId;

    InventQty availQty;

    ;

    itemId = 'PN-VC841A'; 

    inventDim.InventSiteId = 'ENPRO'; //site

    inventDim.InventLocationId = 'IT-KHB'; //WHS

    inventDimParm.initFromInventDim(inventDim);

    inventOnhand = InventOnhand::newParameters(itemId, inventDim, inventDimParm);

    availQty = inventOnhand.availPhysical();

    info(strFmt("%1", availQty));

    }

    Regards,

    Faqru

  • Lalit Jivnani Profile Picture
    Lalit Jivnani 395 on at
    RE: Wrong on hand value for WHS enabled item. X++ Ax2012 R3

    I did every piece of bit..This issue happens only for item with WHS enabled as described by Pradeep..For rest items the code works fine.

  • Lalit Jivnani Profile Picture
    Lalit Jivnani 395 on at
    RE: Wrong on hand value for WHS enabled item. X++ Ax2012 R3

    Hello Pradeep,

    I am encountering the same issue. Can you help me with the piece of code what you did in order to resolve this issue?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,160 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,962 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans