dev vs. smart client finds?

The below code works perfectly in developer:

var ans4 = globals.gSpecialist + globals.gClient;
if (currentcontroller.find()) {
specialist_client = ans4;
currentcontroller.search();
}
var foundOut2 = currentcontroller.getSelectedIndex();
if (foundOut2 == 0) {
//show dialog
thePressedButton = plugins.dialogs.showInfoDialog(“Could not find record for…”, globals.gSpecialist + " - " + globals.gClient, “OK”);
} else {
if (foundOut2 == 1) {
thePressedButton = plugins.dialogs.showInfoDialog(“Found one record for…”, globals.gSpecialist + " - " + globals.gClient, “OK”);
} else {
if (founeOut2 > 1) {
thePressedButton = plugins.dialogs.showInfoDialog(“Duplicate record found for…”, globals.gSpecialist + " - " + globals.gClient, “OK”);
}
}
}

however, in the application server/smart client the code shows one record found when the globals fields are empty…
I checked the database with show all on a different layout and I don’t see a record with blank or null fields…

is my method wrong or do I have corrupted database somehow? I replaced the server databases with the developer ones with the same result?

Thanks for helping…

Hi,

First of all you should use var foundOut2 = currentcontroller.getMaxRecordIndex() and not getSelectedIndex().
Then you will find the number of records and not the index of the current selected record.

Then you should add the lines

if (ans4 == null || ans4 == '')
{
   ans4='^' // search for null value
}

it should work. ^ means search for null values. Otherwise when the globals are empty you do a search with all fields empty
and it will find all records. Also there was a typo founeOut2 > 1 should be founedOut2 > 1

var ans4 = globals.gSpecialist + globals.gClient;
if (ans4 == null || ans4 == '')
{
   ans4='^' // search for null value
}
if (currentcontroller.find()) {
	specialist_client = ans4;
	currentcontroller.search();
}
var foundOut2 = currentcontroller.getMaxRecordIndex();

if (foundOut2 == 0) 
{
	//show dialog
	thePressedButton = plugins.dialogs.showInfoDialog("Could not find record for...", globals.gSpecialist + " - " + globals.gClient, "OK");
} 
else 
{
	if (foundOut2 == 1) 
	{
	thePressedButton = plugins.dialogs.showInfoDialog("Found one record for...", globals.gSpecialist + " - " + globals.gClient, "OK");
	}
	else 
	{
		if (foundOut2 > 1) 
		{
			thePressedButton = plugins.dialogs.showInfoDialog("Duplicate record found for...", globals.gSpecialist + " - " + globals.gClient, "OK");
		}
	}
}

finaly the code could be simpeler :

var ans4 = globals.gSpecialist + globals.gClient;
if (ans4 == null || ans4 == '')
{
   ans4='^' // search for null value
}
if (currentcontroller.find()) {
	specialist_client = ans4;
	currentcontroller.search();
}
var foundOut2 = currentcontroller.getMaxRecordIndex();

switch (foundOut2) {
case 0: 
  thePressedButton = plugins.dialogs.showInfoDialog("Could not find record for...", globals.gSpecialist + " - " + globals.gClient, "OK");
  break;
case 1: 
  thePressedButton = plugins.dialogs.showInfoDialog("Found one record for...", globals.gSpecialist + " - " + globals.gClient, "OK");
  break;
default : 
  thePressedButton = plugins.dialogs.showInfoDialog("Duplicate record found for...", globals.gSpecialist + " - " + globals.gClient, "OK");
}

regards,

Hans

Hans,
You don’t know how long I looked at that and just didn’t see it…

many thanks,
Charles

BTW I don’t know if you are aware of it but using ‘currentcontroller’ must be done with care.
It points to tha main form only and not a form in a tabpanel.
I prefer to refer to the form lik forms.formname.controller…

Hi Marcel,

Agree totally.

And also finding out if there are records could be done without touching the controller, by
using a separate new foundset or using databaseManager.getDataSetByQuery.

In that case the test can be done without the user seeing any find/search happening on the screen.

Regards,

Hans