dev vs. smart client finds?

Questions, tips and tricks and techniques for scripting in Servoy

dev vs. smart client finds?

Postby charles huff » Sat Mar 28, 2009 5:58 pm

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...
charles huff
 
Posts: 41
Joined: Fri Aug 15, 2008 1:24 am

Re: dev vs. smart client finds?

Postby Hans Nieuwenhuis » Sat Mar 28, 2009 8:07 pm

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
Code: Select all
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

Code: Select all
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 :

Code: Select all
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 Nieuwenhuis
Betagraphics
http://www.deltics.nl
http://www.betagraphics.nl

Servoy Version 7.3.1
Java version 1.7.0.x
Database Oracle 11g
User avatar
Hans Nieuwenhuis
 
Posts: 1026
Joined: Thu Apr 12, 2007 12:36 pm
Location: Hengelo, The Netherlands

Re: dev vs. smart client finds?

Postby charles huff » Tue Mar 31, 2009 8:26 am

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

many thanks,
Charles
charles huff
 
Posts: 41
Joined: Fri Aug 15, 2008 1:24 am

Re: dev vs. smart client finds?

Postby IT2Be » Tue Mar 31, 2009 8:33 am

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...
Marcel J.G. Trapman (IT2BE)
SAN partner - Freelance Java and Servoy
Servoy Components - IT2BE Plug-ins and Beans for Servoy
ServoyForge - Open Source Components for Servoy
User avatar
IT2Be
Servoy Expert
 
Posts: 4766
Joined: Tue Oct 14, 2003 7:09 pm
Location: Germany

Re: dev vs. smart client finds?

Postby Hans Nieuwenhuis » Tue Mar 31, 2009 8:44 am

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
Hans Nieuwenhuis
Betagraphics
http://www.deltics.nl
http://www.betagraphics.nl

Servoy Version 7.3.1
Java version 1.7.0.x
Database Oracle 11g
User avatar
Hans Nieuwenhuis
 
Posts: 1026
Joined: Thu Apr 12, 2007 12:36 pm
Location: Hengelo, The Netherlands


Return to Methods

Who is online

Users browsing this forum: No registered users and 34 guests