Help with found sets

Questions, tips and tricks and techniques for scripting in Servoy

Help with found sets

Postby irenem » Tue May 12, 2009 1:56 pm

Hello,

I have a form with 2 tabs: left is a list of all contacts, right the contacts details. I need to find a contact in the right tab by his pk, and select in the left tab the contact.

My method is:
Code: Select all
var x = forms.contacts_join.conjoin_rel2

var serverName = forms.nav_contacts.controller.getServerName()

var query = "SELECT cont_id_rel FROM contacts WHERE cont_id_rel ="+ x;

var dataset = databaseManager.getDataSetByQuery (serverName, query, null, 100);


forms.nav_contacts.controller.loadRecords(dataset)
forms.nav_contacts.controller.loadAllRecords()


Everything works right if the contact is in range of the 200 records loaded on the left side. If not it jumps to the first one.

Can somebody help with this one please?
Irene Meyer

Version: 6.0.5
Java version 1.6.0_29
Mac OS X Version 10.7.3
User avatar
irenem
 
Posts: 279
Joined: Tue Aug 28, 2007 2:09 pm
Location: Netherlands

Re: Help with found sets

Postby Joas » Fri May 15, 2009 2:28 pm

I think you're making it too difficult for yourself.
If you use a relationless tab for both the list and the details, they will share the same foundset. So if you select a record in the list, the details-form will show the same record.

If you really want to load the record yourself, you don't need to do a query, you can just create a dataset yourself:
Code: Select all
var _array = [forms.contacts_join.conjoin_rel2];
var _dataset = databaseManager.convertToDataset(_array);

forms.CONTACT_DETAILS.controller.loadRecords(dataset);
Joas de Haan
Yield Software Development
Need help on your project? yieldsd.com
User avatar
Joas
Site Admin
 
Posts: 842
Joined: Mon Mar 20, 2006 4:07 pm
Location: Leusden, NL

Re: Help with found sets

Postby irenem » Fri May 15, 2009 2:36 pm

Hi Joas,

Thanks for answering. I already have that. But if I perform a find or load in my form view, I will see only the found set in the list view (in my case 1 0r 2 records). What I want (if it's possible) is to see all records in the list and have the one I see in the form view selected in the list.
Irene Meyer

Version: 6.0.5
Java version 1.6.0_29
Mac OS X Version 10.7.3
User avatar
irenem
 
Posts: 279
Joined: Tue Aug 28, 2007 2:09 pm
Location: Netherlands

Re: Help with found sets

Postby jcompagner » Fri May 15, 2009 4:05 pm

but if you do that
Where could the selected one be? It could be the 10.000st record in the all records list foundset..
i dont think there is a real good solution for this. If you start searching in the form view then you just have to let the selection loose in the listview.
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: Help with found sets

Postby jkipling » Tue May 19, 2009 3:15 pm

Irene,

How are you selecting the record in the form view? By simple browsing or a manual servoy find? Could an onRecordSelect method on the form view be of any help?

If I understand you correctly, you want the list view to show all records, but the controller can only hold 200 at a time anyway, so is the problem when the record on the form view is not in the first 200? It seems you should be able to explicitly find and load the selected record on the list form, then why not also just load an extra 199 records using a primary key range or some other range like query on a column that would give you a full set of records.

And as a partial joke of a solution, you could loop through all the records in the list form until the correct one is selected. This would always work because when you loop through records and set the selected index to 200, servoy will load the next 200 records for you. Just stop looping when the primary keys match. Do I understand the problem correctly though?

-Jeremy
jkipling
 
Posts: 99
Joined: Tue Nov 20, 2007 7:46 pm
Location: Natick, MA

Re: Help with found sets

Postby irenem » Tue May 19, 2009 4:53 pm

Jeremy,

I think that you understand the problem correctly. In my form view I have the method described above, a query and loadRecords by a given pk. Load records does the same as a find method, it shows only the requested record. So I tried to loadAllRecords after that, but if the record is not within the first 200 it jumps to the first.

A loop can work with a few records but in a database with thousand of records it would cost a lot of time.

What I'm looking for is a method (like a goToRecord in FileMaker) to jump to a certain record without a find request.
Irene Meyer

Version: 6.0.5
Java version 1.6.0_29
Mac OS X Version 10.7.3
User avatar
irenem
 
Posts: 279
Joined: Tue Aug 28, 2007 2:09 pm
Location: Netherlands

Re: Help with found sets

Postby jcompagner » Tue May 19, 2009 10:07 pm

what you want is foundset.selectRecord(pk)

only problem is that this will only select the record if it is in the loaded pk set (default/init 200)
after that you have to load it first/select it your self by looping
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: Help with found sets

Postby jkipling » Tue May 19, 2009 10:20 pm

Yes sometimes you just have to weigh performance versus functionality. Brute force will always work if you absolutely need the functionality at any cost. I understand that for thousands of records the looping method is not practical.

I still think there must be a way to kind of do what you need by loading just 200 records in the list form that contains the single selected record, then use the foundset.selectRecord(pk). You'd need to write a query for that, that insures it is returning the selected record plus 199 others. Then each time you navigate to a different record on the right tab, reload the foundset in the list tab again with the query. This way you'd be mimicking servoy's controller behavior. All records won't be loaded like you want, but for navigational purposes you have the same result. You could even put a method onRecordSelect of the list form that checks the current index and if it's 200 load the next 200 records.

If there is no column that you can query against currently that would give you the set of 200 records you want in proximity to the selected record, you can create a new column just for indexing purposes, and populate this column for all records with it's controller index and you'd be all set.

Hope this helps,
-Jeremy
jkipling
 
Posts: 99
Joined: Tue Nov 20, 2007 7:46 pm
Location: Natick, MA


Return to Methods

Who is online

Users browsing this forum: No registered users and 48 guests