web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

X++ code to get all the items present in an warehouse

(0) ShareShare
ReportReport
Posted on by 640

Hi All,

I just want to get all the items present in an warehouse with the on hand quantity of an item through X++.

Thanking you in advance.

Thanks & Regards,

Kedar

*This post is locked for comments

I have the same question (0)
  • Sean The Michael Profile Picture
    139 on at
    RE: X++ code to get all the items present in an warehouse

    Hey to further open this question, how do I list the warehouses containing x-item? for example I searched for an item, it will return all the warehouses that contains said item.

  • Brandon Wiese Profile Picture
    17,788 on at
    RE: X++ code to get all the items present in an warehouse

    What does "in" mean without on-hand?  You want to know items with open sales orders or open purchase orders in a specific warehouse?

  • Kedar Dande Profile Picture
    640 on at
    RE: X++ code to get all the items present in an warehouse

    Hi Brandon,

    If I want items present in specific irrespective of on hand then the below code is enough right?

       InventSum                   inventSum;

       InventDim                   inventDimCriteria;

       InventDimParm               inventDimParmCriteria;

       InventDimParm               inventDimParmGroupBy;

       Query                       q;

       QueryBuildDataSource        qbds;

       QueryRun                    qr;

       ;

       inventDimCriteria.InventLocationId = 'W';  // warehouse

       inventDimParmCriteria.InventLocationIdFlag = true;  // filter on warehouse

       inventDimParmGroupBy.ItemIdFlag = true;  // group by item

       q = InventSum::newQuery(q, '', inventDimCriteria, inventDimParmCriteria,       inventDimParmGroupBy);

      qr = new QueryRun(q);

       while (qr.next())

       {

           inventSum = qr.get(tableNum(InventSum));

           info(strFmt("Item number: %1", inventSum.ItemId));

       }

  • Kedar Dande Profile Picture
    640 on at
    RE: X++ code to get all the items present in an warehouse

    Thank you brandon.

  • Verified answer
    Brandon Wiese Profile Picture
    17,788 on at
    RE: X++ code to get all the items present in an warehouse

    Depending on what you call on-hand, this type of approach is quite easy.

    In this code, the filter is on PhysicalInvent, which is PostedQty + Received - Deducted + Registered - Picked.  If you're interested in a more "accounting" type of on-hand, that would be PostedQty + Received - Deducted and would require some tweaks.

        InventSum                   inventSum;
        InventDim                   inventDimCriteria;
        InventDimParm               inventDimParmCriteria;
        InventDimParm               inventDimParmGroupBy;
        Query                       q;
        QueryBuildDataSource        qbds;
        QueryRun                    qr;
        ;
        
        inventDimCriteria.InventLocationId = 'W';  // warehouse
        
        inventDimParmCriteria.InventLocationIdFlag = true;  // filter on warehouse
       
        inventDimParmGroupBy.ItemIdFlag = true;  // group by item
        
        q = InventSum::newQuery(q, '', inventDimCriteria, inventDimParmCriteria, inventDimParmGroupBy);
        
        qbds = q.dataSourceTable(tableNum(InventSum));
        
        qbds.addRange(fieldNum(InventSum, PhysicalInvent)).value(SysQuery::valueNot(0));
        
        qr = new QueryRun(q);
        while (qr.next())
        {
            inventSum = qr.get(tableNum(InventSum));
            
            info(strFmt("Item number: %1", inventSum.ItemId));
        } 


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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Community Member Profile Picture

Community Member 4

#2
Guy Terry Profile Picture

Guy Terry 2 Moderator

#2
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans