Form Extension Framework in D365 on Purchase Order Form

 

Implementing form extension framework in D365 on Purchase Order form


As we know that we don’t make any changes in the already present functionalities of dynamics. So, we created extensions to achieve our changes.


Let’s say, we want to add a filter on all purchase orders so that it only shows those orders which

are either open order or received.

We need to check first the data source and the field it is bind with.


 

·        Form Extension

Creating purchase order form extension.


 As we know that QueryExecuted is always called on the Parent data source. We are working on an extension, so we need to work on Event handlers. Depending on our needs we can decide whether to use OnQueryExecuted or OnQueryExecuting.

 

OnQueryExecuting runs before the super() call of the event

OnQueryExecuted runs after the super() call of the event

 

We need to add our range before the query execution, so we need to work on OnQueryExecuting event handler.

·        Handler class

Now we need a handler class to add the changes we want.

Add a new class and place the copied event handler in it.

Now we add our logic in this handler. First, we get the query that is attached on the form through the sender and then find the range if the range does not exist then we create one and putting the particular values of the status field that we want to show.

 

·        Code:

 class RM_PurchTableEventHandlerr

{   [FormDataSourceEventHandler(formDataSourceStr(PurchTable, PurchTable), FormDataSourceEventType::QueryExecuting)]

    public static void PurchTable_OnQueryExecuting(FormDataSource sender, FormDataSourceEventArgs e)

    {

        Query                   query;

        QueryBuildDataSource    qbds;

        QueryBuildRange         qbr;

       

        query = sender.query(); // getting query from sender

        qbds  = query.dataSourcetable(tablenum(Purchtable));

        qbr   = SysQuery::findOrCreateRange(qbds, Fieldnum(PurchTable, PurchStatus));

 

       //putting filter on two values of the enum PurchStatus

        qbr.value(strfmt("%1,%2",enum2str(PurchStatus::Backorder),enum2str(PurchStatus::Received)));

    }

}

 Now the filter is applied to our desired field. As it only shows the openOrders or Received purchase orders. 





 





Comments

Popular posts from this blog

Batch jobs stuck on WAITING status in AX 2012

Electronic Reporting For Beginners

Computed column and virtual field in D365