Tuesday 25 August 2015

Difference between FINDSET, FINDFIRST and FIND('-')

1. FINDSET :


  • Retrieves set of records.
  • Transaction begins with FINDSET Command. 

2. FINDFIRST : 
  • It will retrieve the first record
  • Retrieves only 1 record, the last one within filter, sorted accordingly.
  • Transactions begins when a call to update the database. (Insert, modify, delete).
  1. Opens the connection with database
  2. fetches the record from database
  3. closes the connection
Example:


IF EmployeeVar.FINDFIRST THEN

      MESSAGE('employee no. %1',EmployeeVar."Employee No.");

Since we are not repeating the process its better to use FINDFIRST if you're fetching only one time from the database.

3. FIND('-') :
  • It will also retrieve the first record
  • Retrieves only 1 record, the last one within filter, sorted accordingly.
  • Transactions begins when a call to update the database. (Insert, modify, delete).
  1. Opens the connection with database
  2. fetches the record from database
  3. doesn't close the connection until the condition is false.


IF EmployeeVar.FIND('-') THEN
REPEAT
      MESSAGE('employee no. %1',EmployeeVar."Employee No.");
 UNTIL EmployeeVar.NEXT=0;


Since we are repeating the process its better to use FIND('-'), it will work fine even if we use FINDFIRST but each time it retrieves the record it opens the connection and before fetching next record it closes the connection. Which reduces performance. 

So, it better to use FIND('-) for repeated retrieval of record. 

Major Differences between Run and RunModal function

I have browsed through lots of blogs and I nowhere found the proper example on how to use RUNMODAL Function. So, I taught of writing this blog so that it might be useful other NAV Developers.

RUN Function :


  • The page is opened and you can still go back to what you were doing on previous page.
  • We can switch to other page which is shown.

RUNMODAL Function:

  • The page is opened and you cannot go back to previous page until MODAL Page is closed.
  • We cannot switch to any other page until current page is closed.


Example :

Scenario :

Assume I want to filter a Customer table who has balance between 10,000 to 1,00000 and to display the filtered values in the Customer list page. You can do the following in the coding part.


Customer.CALCFIELDS(Balance);//Calculates flowfield values
Customer.SETRANGE(Balance,10000,100000);//apply filter range
IF Customer.FINDSET THEN
    PAGE.RUNMODAL(PAGE :: "Customer List",Customer);//opens the filtered list.




Fig. above shows only the filtered customers based on balance between 10,000 to 1,0000 range.