New Form for Items purchase history in purchase order form in AX Dynamics 365

How to create New Form for Items purchase history in purchase order form in AX Dynamics 365

Create Temp Table for PurchHistory data



Create new Query to fetch data from PurchLine Table and add ItemId as Range and keep it open.
its used to fetch data to tmp table in following code.





Create New Form and add below code in Form Data Source.
1. In Data Sources area include PurchLineHistoryTmp table.
2. Set Form Pattern to Simple List
3. In Grid Control Data Source Property Set PurchLineHistoryTmp for mapping
4. Drag and Drop all fields from Table to Form Grid.






Create New Display menu item and assign above form.





Right Click on Form --> View Code and below code.




[Form]
public class PurchLineHistory extends FormRun
{

    InventDimCtrl_Frm_WHS               inventDimFormSetup;
    InventDimParm                       inventDimParmActive;

    QueryBuildRange                     qbrClosed;

    boolean                             calledFromForm;

 
    PurchLineHistoryTmp  PurchLineHistoryTmp1;

    public void init()
    {
        super();

        if (element.args().record() || element.args().lookupField())
        {
            this.InsertData(element.args().record());
            calledFromForm = true;
        }
        PurchId purchid;
     

    }


    /// <param name="_common">
    ///    The record being used to determine what filters to set
    /// </param>
    public void InsertData(Common _common)
    {
        str     filter;
        filter = _common.(fieldNum(PurchLine, ItemId));

         QueryRun                    queryRun;
         Query                       query;
         PurchLine querypurchLine;
        PurchTable purchTable;
        VendPackingSlipJour         vendPackingSlipJour;

        //remove old data
        delete_from s_PurchLineHistoryTmp1;
     
         queryRun = new QueryRun(querystr(PurchLineHistory));

        queryRun.query().dataSourceTable(tableNum(PurchLine)).addRange(fieldNum(PurchLine,ItemId)).value(filter);

     
         ttsbegin;
         while (queryRun.next())
         {
             querypurchLine = queryRun.get(tableNum(PurchLine));

             sPurchLineHistoryTmp1.PurchId = querypurchLine.PurchId;

            select firstonly purchTable where purchTable.PurchId == querypurchLine.PurchId ;
            PurchLineHistoryTmp1.CreatedDate=purchTable.createDate();
            PurchLineHistoryTmp1.SupplierName=purchTable.vendorName();
            //PurchLineHistoryTmp1.CreatedDate=DateTimeUtil::date(purchTable.CreatedDateTime);
            PurchLineHistoryTmp1.QtyOrdered=querypurchLine.QtyOrdered;
             PurchLineHistoryTmp1.QtyReceived=querypurchLine.receivedInTotal();
           //  PurchLineHistoryTmp1.PriceUnit=querypurchLine.PriceUnit;
            PurchLineHistoryTmp1.PurchPrice=querypurchLine.PurchPrice ;
            PurchLineHistoryTmp1.PurchUnit =querypurchLine.PurchUnit ;
             PurchLineHistoryTmp1.PurchStatus=querypurchLine.PurchStatus;
            PurchLineHistoryTmp1.CurrencyCode=querypurchLine.CurrencyCode;

            select firstonly vendPackingSlipJour where vendPackingSlipJour.PurchId == querypurchLine.PurchId ;//order by vendPackingSlipJour.DeliveryDate asc;
            PurchLineHistoryTmp1.ReceivedDate=vendPackingSlipJour.DeliveryDate;

             PurchLineHistoryTmp1.insert();

         }
        ttscommit;

        PurchLineHistoryTmp_ds.executeQuery();

        //args args;
        //args = new Args();
        //args.caller(this);
        //new MenuFunction(menuItemDisplayStr(PurchLineHistory), MenuItemType::Display).run(args);


      //  super();

     
    }

    [DataSource]
    class PurchLineHistoryTmp
    {
        /// <summary>
        ///
        /// </summary>
        public void init()
        {
            super();
        }

        /// <summary>
        ///
        /// </summary>
        public void executeQuery()
        {


            super();
        }

    }

}


Place this Display Menu item menu item in PurchTable Form Area to view form data and Set Parameter as ItemId



Output form will be like below for selected item in Purchase Order Form and displays Items Purchase History from other Purchase Orders with details.



Comments

Post a Comment