Re-Find in Servoy

Hi all,

Is there any way to save the last criteria used in the search mode? or we have to do that programatically?

Thanks in advance.

you can get the SQL to recreate the current foundset by:

var $sql		= databaseManager.getSQL(forms[$form].foundset);
	var $pars		= databaseManager.getSQLParameters(forms[$form].foundset);

to restore it later:

forms[$form].controller.loadRecords($sql, $pars);

In the meanwhile you can store these local vars in globals vars or in a global object.

Hi Marc,

Thank for your response.

In my end it is not working, It is simply going to the find mode with all the records, I just want to store the user entered criteria. Am i doing anything wrong?

Find Method

controller.find();

Search Method

$sql = databaseManager.getSQL(forms.customers.foundset);
$pars = databaseManager.getSQLParameters(forms.customers.foundset);
controller.search(true);

Re-Find Method

controller.find();
forms.customers.controller.loadRecords($sql, $pars);

Thanks,

Hi infop,

You make 2 mistakes in your code.
First of you try to get the SQL and parameters when you are still in find mode. Servoy will only parse and fire them when you use controller.search().
In other words, at any time after loading ANY foundset you can get the used SQL and params with the code Marc showed.

Secondly you try to load the saved SQL and params in findmode. No need for that. Just do the loadRecords(SQL,params) and the foundset is loaded.

Hope this helps.

Hi Infop,

A quick solution,

Save the Search Criteria

//Save Search Criteria
for(var idx=0;idx<alldataproviders.length;idx++) {
	searchCriteria[idx] = controller.getDataProviderValue(alldataproviders[idx]);
}

Load the Search Criteria

//Load the previous search criteria
for(var idx=0;idx<searchCriteria.length;idx++) {		
	if(searchCriteria[idx] != null){
		controller.setDataProviderValue(alldataproviders[idx],searchCriteria[idx]);
	}
}

Save the Search criteria in the Search Method and again Load the previous search criteria in the Re-Find Method.

Hope It helps.

Hi Arup,

That solution does work, but only for searches done in the main form. Any related data that was searched on won’t be covered by this approach.
Just doing the search() and right after that fetch the SQL with params is the simplest way to go (or right before you do another search).

Yes, Robert. You are right.