I have users that may put a form into find mode, but then decide that they no longer wish to run a find (perform a search/run a query). When they ‘cancel’ all they would want to see is the existing foundset without having to run another search to exit find mode.
I got the following advice from Servoy Support regarding this issue:
Hello,
When the user wants to end the find mode, hitting escape in the SmartClient.
If you want to revert to the foundset state before the find was started, you can run keep the foundset in a variable and use a copy of the foundset in find mode.
In case of cancelled find, you can restore the saved foundset.
Regards,
Servoy Support
My question: have anybody tried the above? Any example code from Servoy’s team, please?
Thank you Johan for the reply. However, this is not working. I’m using Servoy 5.2.9. Could this be the problem? (I don’t think it matters.)
This is what I have:
var copyFoundSet = "";
function startFind(event)
{
//Still I need to store foundset in case of cancel
//controller.find();
copyFoundSet = foundset.duplicateFoundSet();
foundset.find();
setElementsInFindMode();
}
function cancelFindShowRecords(event)
{
controller.loadRecords(copyFoundSet);
globals.setupRecordStatus();
setElementsInBrowseMode();
}
is wrong: it sets the variable to be a String, so I guess when you are putting a foundset in it, it stores it as a String (calling it’s toString() method).
You need something like that:
/**
* @properties={typeid:35,uuid:"WHATEVERUUID",variableType:-4}
*/
var copyFoundSet = null;
note the “variableType:-4” in the @properties annotation, it tells Servoy that this is an Object.
I made the change (correction) that Patrick pointed out, but still it doesn’t work. This time the foundset seems to be in the background, but the data is NOT rendered into the form. I think so because the globals.setupRecordStatus() function sets the count of records right -even the previous and next buttons (methods) work without problem, but the data is not showing in the form. I don’t even get an error or warning of any type.
I now have the following:
/**
* @properties={typeid:35,uuid:"WHATEVERUUID",variableType:-4}
*/
var copyFoundSet = null;
/**
* @properties={typeid:24,uuid:"WHATEVERUUID"}
*/
function startFind(event)
{
//Still I need to store foundset in case of cancel
//controller.find();
copyFoundSet = foundset.duplicateFoundSet();
foundset.find();
setElementsInFindMode();
}
/**
* @properties={typeid:24,uuid:"WHATEVERUUID"}
*/
function cancelFindShowRecords(event)
{
controller.loadRecords(copyFoundSet);
globals.setupRecordStatus();
setElementsInBrowseMode();
}
The data is rendered just fine (shown in the form) when I perform a search (controller.search()) or show all records (controller.loadAllRecords()) methods.
I think I am missing something but I haven’t figured it out. I tried setting the copyFoundSet as global variable, I used the copyFoundSet uuid instead (as a: controller.loadRecords(application.getUUID (‘WHATEVERUUID’))), etc. Nothing is working for me. This might be obvious as it was the string definition issue before, but I can’t see it. Any idea?
I hope you didn’t transform the real UUID by ‘WHATEVERUUID’ in your code, did you???
This UUID is a hash that is used by Servoy to uniquely identify each method and properties. You should NEVER tamper it.
You can recreate a UUID, by getting rid of the @properties line and saving again, but be aware that you will have to reattach your methods after that…
I hope you didn’t transform the real UUID by ‘WHATEVERUUID’ in your code, did you???
This UUID is a hash that is used by Servoy to uniquely identify each method and properties. You should NEVER tamper it.
You can recreate a UUID, by getting rid of the @properties line and saving again, but be aware that you will have to reattach your methods after that…
Of course I didn’t!
But to make sure that my method was using an Object and not a String, I removed the old variable, saved the form, and created the new/Object variable (var copyFoundSet = null) — and reattached the methods (although I didn’t need to do that).
Anyway, as I explained above, the method seems to be working, but the data is not showing in the form. Bummer!
You need to exit find mode for controller.loadRecords() to work.
Something like:
function cancelFindShowRecords(event)
{
if (foundset.isInFindMode()) {
foundset.clear();
foundset.search();
}
if (copyFoundSet) controller.loadRecords(copyFoundSet);
globals.setupRecordStatus();
setElementsInBrowseMode();
}
I did as Patrick suggested, and I also tried the method without the if statements. I ‘exited’ the find mode as shown in the methods below, but the ‘genuine cancel find operation’ I’m looking for did not work either.
/**
* @properties={typeid:24,uuid:"4693BEBE-E3B2-429E-A488-A12062D38FCA"}
*/
function cancelFindShowRecords(event)
{
if(foundset.isInFind()){
foundset.clear();
foundset.search();
}
if(copyFoundSet) controller.loadRecords(copyFoundSet);
globals.setupRecordStatus();
setElementsInBrowseMode();
}
and
/**
* @properties={typeid:24,uuid:"4693BEBE-E3B2-429E-A488-A12062D38FCA"}
*/
function cancelFindShowRecords(event) {
foundset.clear();
foundset.search();
controller.loadRecords(copyFoundSet);
globals.setupRecordStatus();
setElementsInBrowseMode();
}
These methods did not work
Also, Patrick said that I need to exit find mode for controller.loadRecords() to work. This is not entirely true. I was using controller.loadRecords() before to reload all records and, at least I was able to stay in the last related record again after reload. The controller.loadRecords() worked without trying to exit the find mode (foundset.isInFind()).
The controller.loadRecords() works as it does the controller.loadAllRecords(). But the controller.loadRecords() does not work when it contains the copyFoundSet variable (var copyFoundSet = foundset.duplicateFoundSet())
I wonder if the Servoy version matter. I am using version 5.2.9. Could this be the issue? If not, have anybody tried this and got it working before? I can upload an small version of the solution if you want to check the issue.
It was working for me when I tried it.
I’m curious to know what might be wrong in your case, perhaps you globals.setupRecordStatus() or setElementsInBrowseMode() calls are messing something up?
I checked. The methods (globals.setupRecordStatus() or setElementsInBrowseMode()) are not the problem. Still I wonder if the version of Servoy is the problem.
I attached the solution and the sql dump file. I removed most of the data from the database. The solution needs other databases’ tables, but they are not necessary to check out the solution. The server name is fcpadb