Storing and retrieving data are the two main activities in Dynamics NAV. While retrieving data, most times we are looking for a specific set of data. To choose our desired data, the system needs to handle large datasets; in this situation, filtering plays a very important role. In this recipe, we will look at the advanced filtering of datasets in the C/AL code.
Create a new codeunit with Object Designer.
Add the following local variable into the
OnRun
trigger:Name
Type
Subtype
GLEntry
Record
G/L Entry
Add the following code into the
OnRun
trigger of the codeunit:GLEntry.RESET; GLEntry.SETCURRENTKEY("Document No.","Posting Date"); GLEntry.SETRANGE("Posting Date",010113D,310113D); GLEntry.SETRANGE("Document Type",GLEntry."Document Type"::Invoice); GLEntry.SETFILTER(Amount,'>%1',25000); IF GLEntry.FINDFIRST THEN MESSAGE('Found!\Document No.: %1\Amount: %2', GLEntry."Document No.", GLEntry.Amount) ELSE MESSAGE('Not Found!');
Save and...