Monday, 16 November 2015

AX 2009 Reports

http://www.slideshare.net/magive249/report-microsoft-dynamics-ax

Through Report Wizard :
http://blog.rahulsharma.in/2009/12/reporting-capabilities-of-ms-dynamics_14.html

A requirement of Creating report , with Grouping / then get top 10 Highest Amount value sorting in Descending.

This is done by using Temp tables - Insert - filter values in to temp, the process to get it sort and insert.  Then send only 10 records through fetch method on to the report.

Use Programmable Section:

I got the requirement to Get details and below get the total Amounts  section .  Total amount section ( should be run only for the 10 Highest Amount Value , this all can be done in Fetch method.








public boolean fetch()
{
    boolean ret     =   false;
    q = qrun.query();

// Loop all the Query and in to Details temp table .
    while(qrun.next())
    {
        purchlineRec    =   qrun.get(tablenum(Purchline));
        inventtblRec    =   qrun.get(tablenum(InventTable));

        this.RelInventTbl(purchlineRec);
        table.ItemId        =   purchlineRec.ItemId;
        table.ItemName      =   purchlineRec.itemName();
        table.PODate        =   PurchTable::find(table.PurchId).createdDate;
        table.PurchId       =   purchlineRec.PurchId;
        table.QtyOrdered    =   purchlineRec.QtyOrdered;
        table.PurchPrice    =   purchlineRec.PurchPrice;
        table.DeliveryDate  =   purchlineRec.DeliveryDate;
        table.LineAmount    =   purchlineRec.LineAmount;
        table.VendName      =   VendTable::find(purchlineRec.VendAccount,false).Name;
        table.insert();
    }
// Insert – only one record per Item in to total temp table – Insert in to Table with Total Sum Amount etc ( fields required in Total Section)

   while select table
    {
        instbl = null;
       select instbl    where instbl.ItemId ==  table.ItemId;
       if(!instbl)
       {
        select sum(LineAmount),sum(QtyOrdered)from tablegrp where tablegrp.itemid == table.itemid;
        instbl.ItemId       =   table.ItemId;
        instbl.TotLineAmt   =   tablegrp.LineAmount;
        instbl.TotPurchQty    =   tablegrp.QtyOrdered;
        instbl.insert();
        }
    }
// Looping total Temp table , order by TotLine Amt – and get detail transactions for Details Temp table  
   while select * from instbl order by TotLineAmt desc where instbl.ItemId  != ""
   {
        while select * from table
            where table.ItemId  ==  instbl.ItemId
            {
                TotLineamt          =   instbl.TotLineAmt;
                TotPurchQty       =   instbl.TotPurchQty;

                //ttscommit;
                if(i <10)
                 element.send(table);
                else
                    break;

            }
            if(i >9)
                break;
             if (TotLineamt)
                {
                    element.execute(1); // Calling Programmable section only at required Part.

                }
              i++;

   }
    ret =   true;
    return ret;
}

No comments:

Post a Comment