
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
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 ;
}
}
if(amount)
{
i = 1;
if(great>amount)
{
great = amount;
itemid = inventtable.ItemId;
Name = inventtable.NameAlias;
}
}
amount = 0;
}
info(strFmt("%1,%2,%3",great,itemid,Name));
}
This will give the most sold product name based on the quantity moved out from the inventory.
Thanks