Skip to main content



No record found.

Microsoft Dynamics AX forum
Suggested answer

Show the most bought product

Posted on by 30

Hey! I am new in AX 2012 and I have a task to do. I need to make a code where I need to get an info with the most bought product from customers. I have to use sales orders. Can somebody help me with this code please? Thank you

  • Suggested answer
    GanapathyS Profile Picture
    GanapathyS 75 on at
    RE: Show the most bought product

    Hello Hogan,

    static void GS_MostSoldProduct(Args _args)
    InventTable inventtable;
    InventTrans inventtrans,inventtrans1;
    real amount = 0;
    real great = 0;
    int i;
    str itemid,Name;
    while select ItemId,NameAlias from inventtable
    while select * from inventtrans order by Qty where inventtrans.ItemId == inventtable.ItemId
    if(inventtrans.StatusIssue == StatusIssue::Sold)
    amount  = inventtrans.Qty ;
    i  = 1;
    great = amount;
    itemid = inventtable.ItemId;
    Name = inventtable.NameAlias;
    amount = 0;

    This will give the most sold product name based on  the quantity moved out from the inventory.


Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .


André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,459 Super User

Martin Dráb Profile Picture

Martin Dráb 225,783 Super User

nmaenpaa Profile Picture

nmaenpaa 101,148


Featured topics

Product updates

Dynamics 365 release plans