AX – D365FO – How to create a custom filter on list or inquiry form in Dynamics AX 2012

During development we have to create custom inquiry forms. Or Form where we can  search and filter records on different criteria.

Consider a scenario, where we have to build custom inquiry form for all saleline. In this inquiry or custom list form, we can filter on records on date, customer and amount or discount.

Lets do this,

Create a form with name custom Sales

From expend its designs and right click on design to open its property window

From property window set its design style to simplelist

Now add new data source on form, and sets create and edit property to no, Because we did not want to insert , update and delete operation  on this form.

Now drag and drop following fields form  data source to grid.

ItemId,CustNumber,SalesQty,SalesPrice,

Now right click on grid and set its datasource to salesline.

Now run the form its look like similar

Now above grid, add  group control and set its column property to 2, also set its visible property to true.

Add String Edit control, and button here.

Right click on String Edit control and set its auto delecaration to true, so we can access this control in x++. Set its name as “txtCustomerNum”. And set its lookup property to always.

Now we are going to create Unbound control with lookup,

Right lock on methods under stringEditcontrol and add lookup method.

Add following code to fill the lookup to customer and Name which belongs to current legal entity.

public void lookup()
{
Query query = new Query();
QueryBuildDataSource queryBuildDataSource, qbds, dsView;
QueryBuildRange queryBuildRange;
 
SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(CustTable), this);
 
sysTableLookup.addLookupField(fieldNum(CustTable, AccountNum));
sysTableLookup.addLookupField(fieldNum(CustTable, Party), false);
 
queryBuildDataSource = query.addDataSource(tableNum(CustTable));
 
qbds = queryBuildDataSource.addDataSource(tableNum(DirPartyTable));
qbds.joinMode(JoinMode::InnerJoin);
qbds.addLink(fieldNum(CustTable, Party), fieldNum(DirPartyTable, RecId));
 
dsView = qbds.addDataSource(tableNum(DirPartyPostalAddressView));
dsView.joinMode(JoinMode::InnerJoin);
dsView.addLink(fieldNum(DirPartyTable, RecId), fieldNum(DirPartyPostalAddressView, Party));
 
 
sysTableLookup.parmQuery(query);
 
sysTableLookup.performFormLookup();
 
 
}

Now run the form lets see the how behave the lookup control.

Man its working. Now check that selected value from this textbox is accessible, then we move to filter the records

Add Click event/ method on button we just added with this string edit button.

And right following code.

void clicked()

{

super();

info(  txtCustomerNumber.text());

}

 

Now run the form, select customer and click on button.

Now right click on Salesline datasource and over rights its execute Query method.

And add following lines to filter it.

public void executeQuery()
{
QueryBuildRange QcustomerFilter;
QcustomerFilter = SysQuery::findOrCreateRange(SalesLine_q.datasourceTable(tableNum(SalesLine)),fieldNum(SalesLine,CustAccount));
if (txtCustomerNumber.text()!=””)
{
QcustomerFilter.value(queryValue(txtCustomerNumber.text()));
 
}
else
{
QcustomerFilter.value(SysQuery::valueUnlimited());
}
super();
}

In button click even add this line code

void clicked()
{
super();
SalesLine_ds.executeQuery();
 
}

Now run the form, select the customer and click on button, you will find the filter records on form

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s