Software Technology Tips

One of the greatest feature of Servoy is that, you can directly interact with the database by using Servoy’s built-in data binding for creating/modifying/editing/searching records using a particular form.  This Tip will address one of the important things while looping through the records of your form.

 We can modify/update the record data of a form by looping through its records. So, we are generally following the below code to do the same.

 

 

// loop through the records

 

          var count = 1;

          var maxCount = controller.getMaxRecordIndex();

          for(var count=1; count<=maxCount; count++) {

                   // select the record

                   controller.setSelectedIndex(count);

                   /* Do any operations with the

                      selected record */

          }

But, there is an issue with this method. You may face the issue when your foundset contain more than 200 records. Servoy only fetches the first 200 records at the start up and then when you select the 200th record; it fetches another set of 200 records to make the foundset of 400 records. Like wise, it will fetch the records. So, if your foundset have 500+ records and you will follow the above method, your script will run only for first 200 records as because the controller.getMaxRecordIndex() method will return 200 at the start up.

Therefore to address the issue, we can follow the below method.

  // loop through the records

          var count = 1;

          var maxCount = databaseManager.getFoundSetCount(foundset);

          for(var count=1; count<=maxCount; count++) {

                   // select the record

                   controller.setSelectedIndex(count);

                   /* Do any operations with the

                      selected record */

          }

 

Here, the databaseManager.getFoundSetCount() method will return the actual record count not only the loaded record counts. So, when ever, it touches the 200th record, Servoy will fetches another set of 200 records and your script will run again for those records.


Related Tags:

Servoy

Author: Arup Sahoo

Related Pages

  • Servoy Programming Skills
  • Servoy Development Projects

Servoy

Let us Connect!

iso 9001 QA25 Red Herring STPI D&B Fastest Growing SME 2013 Award zinnov Nasscom

copyright (c) Mindfire Solutions 2007-2014. Login