Clear last search

On our add/remove/delete records options (they have a navigation bar with prev, next, add, edit, delete and search buttons), we have a generic function that displays a second form (lets call it frmSearch) that allows the user to search records based on different criteria (for example: lets say I’m working with the customers form… I click on the search button and look for all customers whose name starts with ‘B’) . When I find the desired record, I select it from the list and it automatically gets displayed on the parent form (lets call it frmCustomers), because they’re based on the same foundset. This way, I only need to close frmSearch and the desired record will be available for editing. No problem there.

Now, the issue is, whenever the selected record has an index over 200 (lets say the record for customer Bob Jonas has an index of 205), it doesn’t get displayed on the frmCustomers, because, right after the search we execute a foundset.LoadAllRecords (to clear the last search) and that statement loads the first 200 records, so it cant display the selected record 205.

When the user clicks on the search button, I do this:

globals.fSearch("frmSearch",sServerName,sTableName)
		
forms[globals._sCurrFrmName].foundset.loadAllRecords();	// Ex: Customers form

The fSearch function uses the solution model to show a list of records from the parent table and allows filtering (it uses find/search… it doesnt use addFoundsetFilter) . I know the issue is with the loadAllRecords, but I don’t know how else to ‘clear’ the search I did on the frmSearch , if I dont, it won’t allow me to navigate (prev,next) through all of the customers (in the above example I will only be able to navigate through customers whose name start with ‘B’). The code above works well if the selected record from frmSearch is one of the first 200 records of the customers table.

I hope I wasnt so terrible at explaining myself… Any help is appreciated.

Regards,

jd2p

Hi

In the code you use to select the record in the main form use the PK to select the record rather than the index.

If you instruct servoy to get the last record in the foundset based on the foundset count, it will load all records fully for you. foundset.selectRecord will then work as expected.

This can be an expensive operation and should be used sparingly.

if(!foundset.selectRecord(PK)){
		foundset.getRecord(databaseManager.getFoundSetCount(foundset))
		foundset.selectRecord(PK)
	}

Regards

Hi Zuke, thanks a lot for your input. In the search form, we don’t really call a select record by index, we just display the list and when the user selects a record, its automatically selected in the foundset. Im attaching an image of our search form to provide a better idea.

What we do is that we attach the following function the search (Buscar) button (note: we build the form at runtime):

jsForm.newMethod('function doSearch() {if (foundset.find());{foundset[columnName] = "#%" + inputValue + "%";}foundset.search();}') 

As you can see in the attachment, it’s displaying all EMPLOYEES whose name contains the value ‘CA’. Currently the first record from that result list is selected (and it automatically gets selected in the main form). The problem is, that when we go back to the main form, the foundset is still “filtered” due to that last search… so how could I clear that search without losing which was the selected record?

Thanks,
JD