Filtering records
Filter the records is the important part to display the data. By using the filter we can display the necessary data and avoid showing the unnecessary data based on the requirement.
In AX 2012, there is a default filter functionality is there. To use default filter select the form grid and press the ctrl+g shortcut to show/hide the filter options in the grid and then you can enter the values and press the enter key to filter the record.
We can achieve this functionality by using the x++ code.
For example, we need to filter the student results by pass, fail and all option.
I have added one combo box and grid in the form. Based on the combo box selection, I am filtering the student exam results.
Step 1:
Add the unbound combo box with the enum type. So, we can filter the records based on this combo box selected value.
Step 2:
Declare the query build datasource and query build data range variables in the form declarations section.
public classFormRun extends ObjectRun
{
QueryBuildDataSource qbds;
QueryBuildRange qbr;
}
Step 3:
Add the filter code in the combo box selection change event.
public intselectionChange()
{
int ret;
ret = super();
qbds.clearRange(fieldNum(Hari_ExamResult, ExamResult)); //Clear the filter field range
if(ExamResultCombo.valueStr() != '') //Check the combo box has value or not
{
qbr = qbds.addRange(fieldNum(Hari_ExamResult, ExamResult)); //Set the filter field
qbr.value(ExamResultCombo.valueStr()); //Set the filter value
}
Hari_ExamResult_ds.executeQuery(); //Execute the form datasource query to apply the filter
return ret;
}
Some other useful functions like
qbds.clearRanges(); //To clear all ranges
qbr = qbds.findRange(fieldNum(Hari_ExamResult, ExamResult)); //To find the field range already exists or not
Once you understand this code, you can apply this code for different scenarios.
Please try the below filtering records functionality to improve your knowledge in the filtering records.
- Equal
- Not equal
- Like
- Like after
- Between
- Or
- And
- Empty
- Not empty
- Get all datasource names
- Get all datasource ranges
- Clear all ranges
- Clear particular datasource range
- Less than
- Greater than
- Less than or equal to
- Greater than or equal to
- Range is exist or not
- Filter is exist or not
- Find or create range
- Find or create filter
- Query build data source. To string
- Find group by field
- Find field

Like
Report




*This post is locked for comments