Search for an existing record

I have a problem with searching for an existing record, if someone can tell me where I’m wrong. Thank you!!
I try to explain:
I have a table called “PAZIENTI” and I should verify that when I insert a new patient these have not already been entered. The field that allows me to do this verification is “CODICEFISCALE” which is a unique field. Now summarize what I did:

  1. I created an event ajax, selecting the field “CODICEFISCALE” to create the event, I selected the event “ONCHANGE”, and I selected two fields that are passed as parameters: “IDPazienti” and “CODICEFISCALE”;

  2. I entered the following code:

//------------------------------------------------------------
/**

  • Check for an existing record
    */

// SQL statement parameters
$check_table = ‘pazienti’; // Table name
$check_where = “CodiceFiscale = ‘{CodiceFiscale}’”; // Where clause

// Check for record
$check_sql = ‘SELECT *’

. ’ FROM ’ . $check_table
. ’ WHERE ’ . $check_where;

sc_select(dataset, $check_sql);

if (false === {dataset})
{
// Error while accessing database
}
elseif ($dataset->EOF)
{
// IF no record found
$master_field = ‘duplicate’; // Field name on the master application
$master_value = ‘0’; // New value

// Set master value
sc_master_value($master_field, $master_value);
}
else
{
$order_n = array();
$check_sql = “SELECT DISTINCT idPazienti”
. " FROM pazienti"
. " WHERE CodiceFiscale = ‘" . {CodiceFiscale} . "’";
sc_lookup(rs, $check_sql);

if (isset({rs[0][0]})) // Row found
{
$idPazienti[] = {rs[0][0]};
}
$idPazienti = implode(", ", $idPazienti);
var_dump($idPazienti);

// IF record found
$javascript_title = ‘Attention - Existing Patient !!!’; // Javascript message title
$javascript_message = “This Patient [ <font color=‘red’><b>{CodiceFiscale}</b></font> ] has already been inserted previously.<br>Check this code to verify its existence…<br> Check this ID: <font color=‘red’><b> $idPazienti </b></font>”; // Javascript message contents

// Display javascript message
sc_ajax_message($javascript_message, $javascript_title);

// Field parameters
$master_field = ‘duplicate’; // Field name on the master application
$master_value = ‘1’; // New value

// Set master value
sc_master_value($master_field, $master_value);
}


[ATTACH=CONFIG]n82737[/ATTACH] [ATTACH=CONFIG]n82738[/ATTACH]

image1.jpg

image2.jpg

You have an option in your form configuration, for disable show ajax messajes. APPLICATION - SETTINGS - ERROR SETTINGS: AJAX ERROR OUTPUT.

It works great! Thank you!!!