Child pages
  • The Servoy Foundset

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Note

For all programming reference information, see the JSFoundSet API documention in the reference guide.

Forms Bound

...

to a Foundset

A Servoy Form is typically bound to a single database table and the form will always contain a single Foundset object which is bound to the same table. Much of the action in the user interface, such as a user editing data fields, directly affects the form's foundset. Conversely, actions taken on the foundset, such as programmatically editing data, is immediately reflected in the form.

...

The loadRecords method is used to directly modify the underlying query that loads PK data. There are several uses.

Load by a

...

Single PK

This is the simplest approach, which loads a single recordy by its primary key value.

Code Block
foundset.loadRecords(123);

Load by PK

...

Data Set

This approach simply dictates that a foundset will load records based on specified primary key data.

...

Note

Notice the array was converted first to a JSDataset object. This object, which is like a 2-dimensional array, is used to provide support for composite primary keys.

Load by

...

Another Foundset

This approach is useful to essentially copy the query of another foundset.

...

Code Block
// Foundset size grows dynamically as the Foundset is traversed
foundset.getSize(); // returns 200
foundset.setSelectedIndex(200);
foundset.getSize(); // returns 400 because the foundset loaded the next 200 record pks

Iterating Over

...

a Foundset

Often, as part of some programming operation, it is necessary to iterate over part or all of a foundset. There are several approaches to iterating, each having their appropriate usage. In general, a Javascript for or while statement is used to control the flow of execution.

Changing

...

the Selected Index

Perhaps the most intuitive approach is to programmatically change the foundset's selected index property. 

...

See also the JSFoundset's setSelectedIndex method.

Accessing

...

a Record Object

While setting the selected index of the foundset is sometimes necessary, it also contains some overhead and therefore is not always the most efficient way to iterate over a foundset. However, one can iterate in a similar manner, access a record object without changing the selected index of a foundset by using the getRecord method of the foundset.

...

See also the JSFoundset's getRecord method.

Accessing Data Provider Values As

...

an Array

Sometimes the purpose of iterating over a foundset is to access all of the values for a particular data provider. The most efficient way to do this is to obtain an array of values for the foundset's data provider using the getFoundSetDataProviderAsArray method of the databaseManager API.

...

See also the JSFoundset's getFoundSetDataProviderAsArray method.

Using

...

the Foundset Iterator

Sometimes there is more than one user working on the same foundset, possibly inserting or deleting records. When iterating on a foundset, it needs to be ensured that the loop neither skips nor processes twice any record due to the foundset modifications occurred from other clients. Thus, in such cases, a secure iterator is needed to perform the iteration on the foundset.

...

Gliffy Diagram
nameshared foundsets(copy)

Foundsets

...

and Data Broadcasting

A Foundset may be automatically updated when the client receives a Data Broadcast Event . If the data change affected the table to which the foundset is bound, the foundset will be refreshed to reflect the change.

...

The Foundset Updater API is ideal to use for the following situations:

Updating

...

an Entire Foundset

This essentially has the effect of issuing a SQL UPDATE statement using the WHERE clause that constrains the foundset. This presents a significant performance advantage over updating records individually. In the example below, a related foundset is updated, meaning all orders belonging to the selected customer will be affected.

Code Block
var fsUpdater = databaseManager.getFoundSetUpdater(customers_to_orders);
fsUpdater.setColumn('status',101);
fsUpdater.performUpdate();

Updating

...

a Partial Foundset

...

with Different Values

...

for Each Record

The Foundset Updater API can also be used to update part of a foundset. Moreover, unlike the above example, this approach allows for different values for each record. In the example below, the first 4 records (starting from the selected index) are updated by specifying an array of values for each column that is affected.

...

Code Block
var count = 0;
var fsUpdater = databaseManager.getFoundSetUpdater(foundset)
while(fsUpdater.next())
{
	fsUpdater.setColumn('degrees',count++);
}
Note

When When using this approach, it matters what the selected index of the foundset is. The update will start with this record.