# Delayed loading of records

**URL:** <https://forum.servoy.com/t/delayed-loading-of-records/10319>\
**Category:** Classic Servoy\
**Created:** [February 26, 2009, 7:43am UTC](https://forum.servoy.com/t/delayed-loading-of-records/10319 "2009-02-26T07:43:17Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hans\_Nieuwenhuis](https://avatars.discourse-cdn.com/v4/letter/h/87869e/32.png) [@Hans\_Nieuwenhuis](https://forum.servoy.com/u/Hans_Nieuwenhuis)\
**Post date:** [February 26, 2009, 7:43am UTC](https://forum.servoy.com/t/delayed-loading-of-records/10319/1 "2009-02-26T07:43:17Z")

</div>

Hi,

We use a framework that has a master form and below that there are related forms  
in a tabpanel.  
( for instance customer is master and employees and products are related forms)

The related forms are placed using forms.form.elements.tab.addTab(…).

Now the question :

When the related forms are placed i can see ( in the performnace data ) that a query  
is performed for each tabform.

This can be an expensive operation if there are several related forms.  
And it is not of much use to the user, as he can only see one tab at a time !

However, when i scroll trough the records of the master form, I can see that  
only the form on the active tab is queried, not the forms in the non-active tabs.

I would like to place the related forms, but not load records for the forms in tabs  
that are not active, only for the active tab.

Hope this makes sense.

In the 4gl i used there was an option to not do a query on a form until  
it is shown. (delayed …)

Regards,

---

<div class="post-metadata">

**Author:** ![ngervasi](https://avatars.discourse-cdn.com/v4/letter/n/f9ae1b/32.png) [@ngervasi](https://forum.servoy.com/u/ngervasi)\
**Post date:** [February 26, 2009, 9:37am UTC](https://forum.servoy.com/t/delayed-loading-of-records/10319/2 "2009-02-26T09:37:04Z")

</div>

> Hans Nieuwenhuis:  
> I would like to place the related forms, but not load records for the forms in tabs  
> that are not active, only for the active tab.

Have a look at databaseManager.setCreateEmptyFormFoundsets().

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [February 26, 2009, 11:05am UTC](https://forum.servoy.com/t/delayed-loading-of-records/10319/3 "2009-02-26T11:05:12Z")

</div>

how do you use addTab()?

like this?

addTab(x,y, relation,z) ?

do it like this

addTab(x,y, “relationname”,z)

so relation as a string name.

---

<div class="post-metadata">

**Author:** ![Hans\_Nieuwenhuis](https://avatars.discourse-cdn.com/v4/letter/h/87869e/32.png) [@Hans\_Nieuwenhuis](https://forum.servoy.com/u/Hans_Nieuwenhuis)\
**Post date:** [February 26, 2009, 11:12am UTC](https://forum.servoy.com/t/delayed-loading-of-records/10319/4 "2009-02-26T11:12:03Z")

</div>

I use variables so :

forms[\_tab\_form][\_tab\_relation]

````auto
forms[_tab_form].elements.tabs.addTab( forms[_form_at_tab], '', globals.nav.program[globals.nav.program[_program].tab*.program_name].description, null, null, null, null, forms[_tab_form][_tab_relation])*
*```*
*should i put the name of the relation in the variable _tab_relation in " " ??*
*B.t.w. why would using "relation" behave different ??*
*Regards,*
*Hans*
````

---

<div class="post-metadata">

**Author:** ![Hans\_Nieuwenhuis](https://avatars.discourse-cdn.com/v4/letter/h/87869e/32.png) [@Hans\_Nieuwenhuis](https://forum.servoy.com/u/Hans_Nieuwenhuis)\
**Post date:** [February 26, 2009, 11:58am UTC](https://forum.servoy.com/t/delayed-loading-of-records/10319/5 "2009-02-26T11:58:20Z")

</div>

Hi Nicola,

Thanks for your answer, but it does only seem to work with the first (initial) form of the solution.

Also in the help is says :

> Turns off the default foundset record loading for the initial form; must be called as part of the On open method selected in the Solutions Settings dialog; similar to calling foundset.clearFoundset as a form onLoad event.

Regards,

Hans

---

<div class="post-metadata">

**Author:** ![ngervasi](https://avatars.discourse-cdn.com/v4/letter/n/f9ae1b/32.png) [@ngervasi](https://forum.servoy.com/u/ngervasi)\
**Post date:** [February 26, 2009, 12:01pm UTC](https://forum.servoy.com/t/delayed-loading-of-records/10319/6 "2009-02-26T12:01:27Z")

</div>

From my understanding that should affect all newly created foundsets, if you set it to not load records when you show a form with a new foundset that foundset will be empty instead of containing all the table records. I’ve never used it tough.

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [February 26, 2009, 12:41pm UTC](https://forum.servoy.com/t/delayed-loading-of-records/10319/7 "2009-02-26T12:41:08Z")

</div>

> Hans Nieuwenhuis:  
> I use variables so :  
> forms[\_tab\_form][\_tab\_relation]  
> B.t.w. why would using “relation” behave different ??
> 
> > so \_tab\_relation is a string, the relation name? just put that one in directly instead of getting the relation
> > 
> > It is very simple why just the string will behave different. when you do
> > 
> > forms.x.relation
> > 
> > you touch the relation so it has to and will be loaded so that you can do stuff on it like asking or the size or getting a record and its data
> > 
> > but if you just give the add tab a string then you dont touch the relation so it will not be loaded and internally it stays a string until you select the tab and the tab looks up the relation based on that string.

---

<div class="post-metadata">

**Author:** ![Hans\_Nieuwenhuis](https://avatars.discourse-cdn.com/v4/letter/h/87869e/32.png) [@Hans\_Nieuwenhuis](https://forum.servoy.com/u/Hans_Nieuwenhuis)\
**Post date:** [February 26, 2009, 1:28pm UTC](https://forum.servoy.com/t/delayed-loading-of-records/10319/8 "2009-02-26T13:28:26Z")

</div>

Hi Johan,

So i changed

````auto
forms[_tab_form].elements.tabs.addTab( forms[_form_at_tab], '', globals.nav.program[globals.nav.program[_program].tab*.program_name].description, null, null, null, null, forms[_tab_form][_tab_relation])*
*```*
*to*
*```*
<em>forms[_tab_form].elements.tabs.addTab( forms[_form_at_tab], '', globals.nav.program[globals.nav.program[_program].tab*.program_name].description, null, null, null, null, _tab_relation)*</em>
_*```*_
_*I assume that is what You meant ??*_
_*This seems to do the trick, I'l do some more testing.*_
_*Thanks very much Johan, Servoy still has features I am not aware of (yet).*_
_*Regards,*_
_*Hans*_
````

---

<div class="post-metadata">

**Author:** ![Hans\_Nieuwenhuis](https://avatars.discourse-cdn.com/v4/letter/h/87869e/32.png) [@Hans\_Nieuwenhuis](https://forum.servoy.com/u/Hans_Nieuwenhuis)\
**Post date:** [February 27, 2009, 7:55am UTC](https://forum.servoy.com/t/delayed-loading-of-records/10319/9 "2009-02-27T07:55:28Z")

</div>

Hi Johan,

Is my code correct now ?

The number of queries fired is a lot less now, BUT there are still some  
queries that should not be fired.

I guess I can create a case for this but first I want to be sure that my code is correct.

Regards,

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [February 27, 2009, 9:40am UTC](https://forum.servoy.com/t/delayed-loading-of-records/10319/10 "2009-02-27T09:40:22Z")

</div>

yes that code is fine  
As long as you just point to the relation by name and not the object itself it shouldnt be loaded.

---

<div class="post-metadata">

**Author:** ![Hans\_Nieuwenhuis](https://avatars.discourse-cdn.com/v4/letter/h/87869e/32.png) [@Hans\_Nieuwenhuis](https://forum.servoy.com/u/Hans_Nieuwenhuis)\
**Post date:** [February 27, 2009, 1:28pm UTC](https://forum.servoy.com/t/delayed-loading-of-records/10319/11 "2009-02-27T13:28:31Z")

</div>

Hi Johan,

Just created a very simple form : master with empty tab panel and 3 related child forms.

The code I use to place the forms on the tabs is :

```auto
suc = forms.par1s.elements.tabs.addTab( forms.ch1, 'ch1', 'ch1', null, null, null, null, 'par1s_to_ch1s')

suc = forms.par1s.elements.tabs.addTab( forms.ch2, 'ch2', 'ch2', null, null, null, null, 'par1s_to_ch2s')

suc = forms.par1s.elements.tabs.addTab( forms.ch3, 'ch3', 'ch3', null, null, null, null, 'par1s_to_ch3s')

```

when i start the solution the parent form is shown with now tabs. A buttonclick executes the above code and the 3 tabs are there.

Only the tab for ch1 is active, i do not switch to the other tabs.

When I then look at the performance data in Servoy Server Page I see that there where queries done for all  
3 childforms.

This should not be the case right ??

Regards,

---

<div class="post-metadata">

**Author:** ![Hans\_Nieuwenhuis](https://avatars.discourse-cdn.com/v4/letter/h/87869e/32.png) [@Hans\_Nieuwenhuis](https://forum.servoy.com/u/Hans_Nieuwenhuis)\
**Post date:** [February 27, 2009, 1:31pm UTC](https://forum.servoy.com/t/delayed-loading-of-records/10319/12 "2009-02-27T13:31:47Z")

</div>

The output in Servoy Server Page is :

00:00:016 1 00:00:016 Find select \* from ( select ID from CH2S order by ID asc ) where rownum \<= ?  
00:00:000 1 00:00:000 Find select \* from ( select ID from CH1S order by ID asc ) where rownum \<= ?  
00:00:000 1 00:00:000 Find select \* from ( select ID from CH3S order by ID asc ) where rownum \<= ?  
00:00:000 1 00:00:000 Find select \* from ( select ID, PAR1\_ID, NAAM from CH1S where ID in (?, ?, ?, ?, ?, ?) ) where rownum \<= ?  
00:00:000 3 00:00:000 Relation select \* from ( select ID, PAR1\_ID, NAAM from CH1S where PAR1\_ID = ? order by ID asc ) where rownum \<= ?  
00:00:000 1 00:00:000 Find select \* from ( select ID, PAR1\_ID, NAAM from CH2S where ID in (?, ?, ?, ?, ?, ?) ) where rownum \<= ?  
00:00:000 1 00:00:000 Find select \* from ( select ID, PAR1\_ID, NAAM from CH3S where ID in (?, ?, ?, ?, ?, ?) ) where rownum \<= ?

so 6 finds and 1 relation, does that mean that when the childforms are loaded, they do a find by themself ??

Regards,

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [February 27, 2009, 4:05pm UTC](https://forum.servoy.com/t/delayed-loading-of-records/10319/13 "2009-02-27T16:05:56Z")

</div>

the first 3 looks like pk selects

the 4th is a fill of row data of 1 of the above pk selects

then 1 relation query

and again 3 row data queries for the other 2

so there is only 1 relation query there. But 3 are existing foundsets that do a load or refresh  
So they where already loaded.

---

<div class="post-metadata">

**Author:** ![Hans\_Nieuwenhuis](https://avatars.discourse-cdn.com/v4/letter/h/87869e/32.png) [@Hans\_Nieuwenhuis](https://forum.servoy.com/u/Hans_Nieuwenhuis)\
**Post date:** [February 27, 2009, 4:12pm UTC](https://forum.servoy.com/t/delayed-loading-of-records/10319/14 "2009-02-27T16:12:12Z")

</div>

Oke, but all queries are executed when the above code is executed.

Maybe the 3 finds are done when the forms in the tabs are loaded ??

They are the result of the 3 addTabs, i cleared the performance data, just before pressing the button.

Regards,

Hans

---

<div class="post-metadata">

**Author:** ![Hans\_Nieuwenhuis](https://avatars.discourse-cdn.com/v4/letter/h/87869e/32.png) [@Hans\_Nieuwenhuis](https://forum.servoy.com/u/Hans_Nieuwenhuis)\
**Post date:** [February 27, 2009, 4:31pm UTC](https://forum.servoy.com/t/delayed-loading-of-records/10319/15 "2009-02-27T16:31:58Z")

</div>

Hi,

I now added “databaseManager.setCreateEmptyFormFoundsets()” to the onOpen method of the solution.

Now the only query (so not 7) that is done when i push the button is :

00:00:000 3 00:00:000 Relation select \* from ( select ID, PAR1\_ID, NAAM from CH1S where PAR1\_ID = ? order by ID asc ) where rownum \<= ?

This is what Nicola already suggested.

Thanks guys, i guess this is the way the cut down on non-needed queries : only use relation name and use setCreateEmptyFormFoundsets.

Now you have to use loadRecords or loadAllRecords on the parent form, the related forms are populated automatically.

Have a great weekend !!

Regards,

Hans

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [February 27, 2009, 4:45pm UTC](https://forum.servoy.com/t/delayed-loading-of-records/10319/16 "2009-02-27T16:45:36Z")

</div>

ahh the forms you do touch when you set them as tabpanels do load first there normal query… (so that are the 2 queries per form)

I could change that that you also can use addTab with “formname” instead of a form…  
then that is also lazy.

---

<div class="post-metadata">

**Author:** ![Hans\_Nieuwenhuis](https://avatars.discourse-cdn.com/v4/letter/h/87869e/32.png) [@Hans\_Nieuwenhuis](https://forum.servoy.com/u/Hans_Nieuwenhuis)\
**Post date:** [February 27, 2009, 4:52pm UTC](https://forum.servoy.com/t/delayed-loading-of-records/10319/17 "2009-02-27T16:52:57Z")

</div>

Would be a geat feature !! to be able to choose wether the foundset is initially loaded or not.

Regards,

Hans

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [February 27, 2009, 9:51pm UTC](https://forum.servoy.com/t/delayed-loading-of-records/10319/18 "2009-02-27T21:51:13Z")

</div>

you can already choose that by that setting that setting you now have.

if you can add a tab by relationname and formname instead of relation itself and the form itself it is just a bit more lazy

---

<div class="post-metadata">

**Author:** ![Hans\_Nieuwenhuis](https://avatars.discourse-cdn.com/v4/letter/h/87869e/32.png) [@Hans\_Nieuwenhuis](https://forum.servoy.com/u/Hans_Nieuwenhuis)\
**Post date:** [February 28, 2009, 9:16am UTC](https://forum.servoy.com/t/delayed-loading-of-records/10319/19 "2009-02-28T09:16:20Z")

</div>

Yes,

But then you also can choose a different behaviour per form.

The setting I use now, is used for all forms.

For instance i would like that behaviour for forms on a tabpanel,  
not for the master form.

Regards,

Hans

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [February 28, 2009, 10:06pm UTC](https://forum.servoy.com/t/delayed-loading-of-records/10319/20 "2009-02-28T22:06:03Z")

</div>

i think you can also already do that

in the onload of the forms that you place in the tab you do this:

function onload()  
{  
foundset.clear();  
}

if you do that then that form will also not load data.

[Next page](https://forum.servoy.com/t/delayed-loading-of-records/10319.md?page=2)
