Field validation

I want to validate a field depending on a query based on some fields in the current form.

The following works :

var maxReturnedRows = 1
var query = 'select klant from component where compno = ? and klant = ?'
var args = new Array();
args[0] = forms.frm_call_detail_tab1.foundset.compno;
args[1] =  forms.frm_call_detail_tab1.foundset.site_relc;
application.output('inp = ' + forms.frm_call_detail.compno + '==' + forms.frm_call_detail.site_relc);
var dataset = databaseManager.getDataSetByQuery(forms.component.controller.getServerName(), query, args, maxReturnedRows);

application.output(dataset.getMaxRowIndex());
if (dataset.getMaxRowIndex() != 1)
{
  application.output('wrong');
  return false;
}
else
{
  application.output('oke');
  return true;
 }

I wonder if this is the right way to do it ???

:oops:

forgot info :

Version 3.5 rc2-build 507
Java version 1.6.0_01-b06 (Windows XP)
Database Oracle 10gr2

I guess you could do it like this.

An alternative is to do a find/search on the (controller of a) form.

BTW if you set the max rows to 1 (if even necessary) you can evaluate like:

if (dataset.getMaxRowIndex()) 
{ 
  application.output('oke'); 
  return true; 
} 
else 
{ 
  application.output('wrong'); 
  return false; 
 }

instead of:

if (dataset.getMaxRowIndex() != 1) 
{ 
  application.output('wrong'); 
  return false; 
} 
else 
{ 
  application.output('oke'); 
  return true; 
 }

A (little) advantage of the way javascripting can be scripted :)

Thanks Marcel,

I think i can not use Find/Search.

It has to work as follows :

  1. the user enters a value in the site_relc field
  2. the user enters a value in the compno field

if these 2 belong together, the user can save/go to the next field

if they are not, the user gets an error message and he can not move out of the compno field until he enters a valid compno.

If the user exits the application while the compno is wrong, the original value is (automaticly) restored.

( I will also make it work the other way around so user enters site_relc it has to match with the compno, etc …)