Parameters
serverName - the specified server name.
tableName - the specified table name.
Example
var fs =
databaseManager.getFoundSet(controller.getServerName(),‘empl
oyees’);
var record = fs.getRecord(10);
record.emp_name = ‘pipo’;
record. = 100;
databaseManager.saveData();
This behavior is not like I expect. I want to use this method when I want a complete separated foundset, not linked to any form. But the function returns an already existing foundset on this table.
The behavior how it works now (it returns an existing foundset) corresponds with the example, because otherwise after the call to databaseManager.getFoundSet, the foundset doesn’t have records. And in this example it already has a record with index 10 without a find/search or loadRecords()
That is not what I expected and I don’t think this is good behavior. If I want a copy of an existing foundset, I can use the DuplicateFoundSet method.
Is this a bug?
Is there another way I can obtain the behavior I need (I need foundset to add new records with data broadcasting, so Raw SQL is not a solution)
Have you tried to actually load something different in this foundset? So for example, if you change your code to
var fs = databaseManager.getFoundSet(controller.getServerName(),‘employees’); fs.loadAllRecords();
// or fs.loadRecords(someQuery, someQueryArgs);
var record = fs.getRecord(10);
record.emp_name = ‘pipo’;
record. = 100;
databaseManager.saveData();
No I noticed that I had to use fs.clear() before using the foundset
Probably for the same reason.
Foundset was not empty.
I had some troubles with it.
When using fs.clear() these problems were solved.
Unfortunately not the problem I faced today
In my opinion the databaseManager.getFoundSet should ALWAYS return a new (empty) instance of a FoundSet.
I am not 100% sure what kind of foundset it does return. I use this method to create foundsets for tables I don’t even have a form for. Then without doing something like loadAllRecords(), you have nothing.
Problem is that when you have a foundset for some loaded form, that the databaseManager.getFoundSet() will see my created foundset and the foundset on the form as 1 foundset. I see it because I see that when I do fs.NewRecord() on my local foundset, that I see a new record added on my form after saveData()
I get no results back if I want to get a specific record based on a loaded foundset, like:
var vFoundset = databaseManager.getFoundSet(currentcontroller.getServerName(),currentcontroller.getTableName())
var vCurrentRecord = vFoundset.getRecord(vFoundset.getSelectedIndex())
The foundset contains records, but is this a valid way of getting a record?
The foundset contains records, but is this a valid way of getting a record?
What foundset are you talking about here? A foundset linked to one of your forms?
var vFoundset = databaseManager.getFoundSet(currentcontroller.getServerName(),currentcontroller.getTableName())
The vFoundset should have a new instance of a foundset completely unrelated to whatever form that uses the same table.
So in my opinion it is correct that the foundset should be empty here and the getRecord() method should not give any records.
So this is an invalid way to get a record, because in your coding there should not be no records in your foundset.
I would use it like this:
var vFoundset = databaseManager.getFoundSet(currentcontroller.getServerName(),currentcontroller.getTableName())
vFoundset.clear();
vFoundset.find();
vFoundset['some field'] = 'some value'
vFoundset.search();
if (vFoundset.getSize() > 0)
var vCurrentRecord = vFoundset.getRecord(vFoundset.getSelectedIndex())
martinh:
What foundset are you talking about here? A foundset linked to one of your forms?
Hi Martin, I’m indeed talking about a foundset linked to one of my forms.
The vFoundset should have a new instance of a foundset completely unrelated to whatever form that uses the same table.
So in my opinion it is correct that the foundset should be empty here and the getRecord() method should not give any records.
So this is an invalid way to get a record, because in your coding there should not be no records in your foundset.
Roger that
I would use it like this:
var vFoundset = databaseManager.getFoundSet(currentcontroller.getServerName(),currentcontroller.getTableName())
vFoundset.clear();
vFoundset.find();
vFoundset[‘some field’] = ‘some value’
vFoundset.search();
if (vFoundset.getSize() > 0)
var vCurrentRecord = vFoundset.getRecord(vFoundset.getSelectedIndex())
currentcontroller.getServerName(),currentcontroller.getTableName()
```But beware of the fact that 'currentcontroller' returns the controller of the main form and not the form that is shown in a tab panel (important when you use this in a global method)!
the getFoundSet thing is a nice feature, but be carefull!
if you don’t have ANY form attached to this table (foundset) the table is NOT exported if you use the solution export function in Servoy!
I have allready filled a request/issue for this in the support solution!
Boy am I confused. How do I attach a form’s foundset to a variable for the purpose of quickly looping through the records? I used to do this:
var fs = forms.formName.foundset;
for ( var i = 1 ; i <= fs.getSize() ; i++ )
{
var record = fs.getRecord( i );
record.columnName = "Some Value";
}
Granted, this code does still work, but there had to be a reason for removing the foundset functions from the form tree. I just don’t quite understand what that reason could be. Can someone enlighten me a bit? Forgive me, but I have always been a little fuzzy on the concept of foundsets.
The form still has a property “foundset” that you can grab. Your code is still valid. The reason why the foundset has been moved to the databaseManager is probably that the foundset is not tied to a form, but rather the opposite: a form has a foundset. Another reason might be that you can now create a foundset without ever having created a form based on the foundset’s table. So nothing has changed for you. Things just show up in the method editor under databaseManager.