How to: Traverse a form - tab panel and tab elements

I have created a form from a solution model, then added two tab panels and on each tab panel added one or more tabs with an associated form.
That part seems to be created ok.
I need to go into find mode for the top most form (note that all the forms in the tab panels and the top most form have the same foundset) and ensure that all the fields showing on each form are “empty” so the user can enter only those fields on which to search.
The issue is that the first record of the foundset is being shown and of course the fields are not empty.
I assume that I have to clear these fields right after entering find mode - so I call a method: clear_fields.

clear fields design: traverse the top level form, find each tab panel and each tab on that tab panel and extract the form (the form name actually) then clear each element that begins with ‘fld_’. (the only fields allowed to search).

The code snippet is as follows (at the top level form):

 //EXECUTED ONLY WHEN IN FIND MODE
	for (var i = 0; i < elements.allnames.length; i++) {
		var name = elements.allnames[i];
		
		if(name.indexOf('fld_',0) == 0){ //only those elements that have a name beginning with 'fld_' are allowed to be set null/empty
			var dataprovider = elements[name].getDataProviderID();

			controller.setDataProviderValue(dataprovider,null);
				
		} else if (name.indexOf('tab_panel_',0) == 0){//tab_panel_1 and tab_panel_2 are the defined names when creating from solution model
			//find all the tabs and the form on each!
			var max = elements[name].getMaxTabIndex();
			for (var j = 0; j < max; j++){
				var tab_frm_name = elements[name].getTabFormNameAt(j); //FAILS - returns null
                    .....

The code fails to find a form at the tab index.

So my question is this:
How is it best to traverse the elements on a form, find a tab panel and then find all the tabs on the panel and extract the form name for each?

Servoy 6.0.6

HI Tom,

I do something like below to find tabpanels, it may be of use…

function dm_readonly(readOnly, formName) {
	
	if(!formName){
		formName = controller.getName();
	}
	
	var tabFrm
	forms[formName].controller.readOnly = readOnly; //Set parent form

	for ( var i = 0 ; i < forms[formName].elements.length ; i++ ) {
		var type = forms[formName].elements[i].getElementType();
		if(type == ELEMENT_TYPES.TABPANEL){
			 
			var tabCount = forms[formName].elements[i].getMaxTabIndex();
			for ( var j = 1 ; j <= tabCount ; j++ ){
				tabFrm = forms[formName].elements[i].getTabFormNameAt(j);
				application.output(tabFrm);
				//forms[tabFrm].dm_readonly(readOnly);
				dm_readonly(readOnly, tabFrm)
			}
		}
	}
}

I found my error:
the tab indices start at 1 not zero :oops:

But thanks for reminding me to use the element type (TABPANEL) where possible!