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)

Stock management: how to get all the IN & OUT stock (inventory) transactions in a sql query (movement, adjustment, stock receipt, sales etc).

(0) ShareShare
ReportReport
Posted on by

Stock management: how to get all the IN & OUT stock (inventory) transactions in a sql query (movement, adjustment, stock receipt, sales etc).

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Vilmos Kintera Profile Picture
    46,149 on at
    RE: Stock management: how to get all the IN & OUT stock (inventory) transactions in a sql query (movement, adjustment, stock receipt, sales etc).

    The stock transactions are based on InventTransOrigin and InventTrans table.

    InventTrans.InventTransId = InventTransOrigin.RecId

    InventTransOrigin.ReferenceCategory will tell you what is the originator (Sales, Purchase, Transfer, whatever). Then on InventTrans, the StatusIssue and StatusReceipt fields are showing what has happened to the transaction (Received, Purchased, Sold, etc.).

    With this, you should be able to start building the joins and the where clause to show exactly the combinations you are interested in. A functional consultant should be able to help with the various combinations of statuses.

  • Suggested answer
    ColbyGallagher Profile Picture
    3,666 on at
    RE: Stock management: how to get all the IN & OUT stock (inventory) transactions in a sql query (movement, adjustment, stock receipt, sales etc).

    Instead of writing SQL, you could just use the Inventory Value cube if you have them deployed for this.

  • Verified answer
    Community Member Profile Picture
    on at
    RE: Stock management: how to get all the IN & OUT stock (inventory) transactions in a sql query (movement, adjustment, stock receipt, sales etc).

    Many thanks vilmos.

    I forgot to mention the version of AX, I'm working on AX 2012 R2. The field name 'InventTransId' is not available and matched with 'INVENTTRANSORIGIN'.

    Below is the actual query. 

    SELECT T2.REFERENCECATEGORY, *
    FROM INVENTTRANS AS T1
    INNER JOIN INVENTTRANSORIGIN AS T2 ON T1.INVENTTRANSORIGIN = T2.RecId;

    I have one more issue now to link financial dimensions with these two tables as I have to filter using Department and Cost Center.

    Please let me know "how to link the financial dimension".

  • Verified answer
    Vilmos Kintera Profile Picture
    46,149 on at
    RE: Stock management: how to get all the IN & OUT stock (inventory) transactions in a sql query (movement, adjustment, stock receipt, sales etc).

    Ok good to hear you have found the link.

    The dimensions belong to the postings behind the transactions, and have been answered in this topic:

    community.dynamics.com/.../186442

    InventTransPosting and DimensionAttribute* tables are involved. If you navigate in AX to AOT > Data Dictionary > Tables > InventTrans > Relations, you should be able to find the connection to physical and financial postings, then from there the financial dimensions.

  • Community Member Profile Picture
    on at
    RE: Stock management: how to get all the IN & OUT stock (inventory) transactions in a sql query (movement, adjustment, stock receipt, sales etc).

    Many Thanks for the help. It worked. Below is the final query;

    SELECT CASE

    WHEN T2.REFERENCECATEGORY=0 THEN 'Sales'

    WHEN T2.REFERENCECATEGORY=3 THEN 'Purchase'

    WHEN T2.REFERENCECATEGORY=4 THEN 'Transaction'

    WHEN T2.REFERENCECATEGORY=5 THEN 'Stock Adjustment'

    WHEN T2.REFERENCECATEGORY=6 THEN 'Transfer'

    WHEN T2.REFERENCECATEGORY=20 THEN 'Fixed Asset' ELSE 'Others' END AS TransactionType,

    CASE WHEN T1.QTY < 0 THEN 'OUT' ELSE 'IN' END AS StockMovementType,

    ISNULL(T52.NAME, N'') AS Department, ISNULL(T62.NAME,N'') AS RequestedBy, T1.VOUCHERPHYSICAL, T1.DATEPHYSICAL, T1.ITEMID, T32.NAME, T1.QTY, T1.COSTAMOUNTPHYSICAL,

    CASE WHEN ISNULL(T1.PACKINGSLIPID,N'')='' THEN T1.INVOICEID ELSE T1.PACKINGSLIPID END AS SupplierRef  

    FROM INVENTTRANS AS T1

    INNER JOIN INVENTTRANSORIGIN AS T2 ON T1.INVENTTRANSORIGIN =  T2.RECID  

    LEFT JOIN ECORESPRODUCT AS T3 ON T3.DISPLAYPRODUCTNUMBER = T1.ITEMID

    LEFT JOIN ECORESPRODUCTTRANSLATION AS T32 ON T32.PRODUCT = T3.RECID AND T32.LANGUAGEID = 'en-us'

    LEFT JOIN INVENTTRANSPOSTING AS T4 ON T4.INVENTTRANSORIGIN=T1.INVENTTRANSORIGIN AND T4.VOUCHER = T1.VOUCHERPHYSICAL AND T4.ISPOSTED=1

    LEFT JOIN DEFAULTDIMENSIONVIEW AS T5 ON T5.DEFAULTDIMENSION = T4.DEFAULTDIMENSION AND T5.NAME = 'Department'  

    LEFT JOIN DIMATTRIBUTEOMDEPARTMENT AS T52 ON T52.VALUE = T5.DISPLAYVALUE

    LEFT JOIN DEFAULTDIMENSIONVIEW AS T6 ON T6.DEFAULTDIMENSION = T4.DEFAULTDIMENSION AND T6.NAME = 'Worker'  

    LEFT JOIN DIMATTRIBUTEHCMWORKER AS T62 ON T62.VALUE = T6.DISPLAYVALUE

    WHERE T1.DATAAREAID IN(@DataAreaId)

  • Verified answer
    ColbyGallagher Profile Picture
    3,666 on at
    RE: Stock management: how to get all the IN & OUT stock (inventory) transactions in a sql query (movement, adjustment, stock receipt, sales etc).

    LEFT JOIN ECORESPRODUCT AS T3 ON T3.DISPLAYPRODUCTNUMBER = T1.ITEMID

    INNER JOIN INVENTTABLE AS T999 ON T999.ITEMID = T1.ITEMID 

    INNER JOIN ECORESPRODUCT AS T3 ON T3.RECID = T999.PRODUCT

    You should always join to ecoresproduct through inventtable to get the product, as ItemID and DisplayProductNumber can be different.  

  • Community Member Profile Picture
    on at
    RE: Stock management: how to get all the IN & OUT stock (inventory) transactions in a sql query (movement, adjustment, stock receipt, sales etc).

    Many Thanks Colby.

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
Martin Tocauer Profile Picture

Martin Tocauer 4

#1
Community Member Profile Picture

Community Member 4

#3
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans