While building the function to create a real cancel find function, I was using this example found in Servoy’s built-in documentation:
duplicateFoundSet(): JSFoundSet<db:/fcpadb/fcpa_entities>
Get a duplicate of the foundset.
var dupFoundset = foundset.duplicateFoundSet();
foundset.find();
//search some fields
var count = foundset.search();
if (count == 0)
{
plugins.dialogs.showWarningDialog('Alert', 'No records found','OK');
controller.loadRecords(dupFoundset);
}
It wasn’t working because the controller.loadRecords resulted in a found set that could not be retrieved in the form. The found set was there, but the controller was not loading the found set.
This is the code I use and works fine:
//first I defined the variable to store or copy in the duplicated found set
var copyFoundSet = null;
//a standard find
function startFind(event)
{
copyFoundSet = foundset.duplicateFoundSet();
foundset.find();
setElementsInFindMode();
}
//the real cancel function
function cancelFindShowRecords(event) {
foundset.search();
setElementsInBrowseMode();
//controller.loadRecords(copyFoundSet);
foundset.loadRecords(copyFoundSet);
}
//the search that retrieves prior found set in case nothing is found
function performSearch (event)
{
var foundRecords = foundset.search();
setElementsInBrowseMode();
if(foundRecords == 0)
{
plugins.dialogs.showErrorDialog( 'Search Exception', 'No records were found matching your search request.\nTry your search again', 'Ok');
//controller.loadRecords(copyFoundSet)
foundset.loadRecords(copyFoundSet);
}
}
Just feel like sharing this with newbies because I spent a considerably amount of time until I found the glitch.
Best,
Carlos