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

Announcements

No record found.

News and Announcements icon
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)
  • Verified answer
    Brandon Wiese Profile Picture
    17,790 on at

    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));
        } 


  • Kedar Dande Profile Picture
    640 on at

    Thank you brandon.

  • Kedar Dande Profile Picture
    640 on at

    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));

       }

  • Brandon Wiese Profile Picture
    17,790 on at

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

  • Sean The Michael Profile Picture
    139 on at

    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.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 39

#2
Michel ROY Profile Picture

Michel ROY 14

#3
imran ul haq Profile Picture

imran ul haq 8

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans