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.
OnQueryExecuting
runs before the super() call of the event
OnQueryExecuted
runs after the super() call of the event
·
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
Post a Comment