How get duplicate found in Contract module

Hello everyone
I want to know how can i get the error msg : duplicate found, if i have the same contracts

I’d recommend taking a look at how this is done in Accounts/Contacts/Leads module.

You could write a before save logic hook to do a check and cancel the save if there’s a duplicate.

I already created a logic_hook file with :

$hook_array[‘before_save’] = Array();
$hook_array[‘before_save’][] = Array(1,‘validateCtr’,‘custom/modules/P_Contrat/validateCtr.php’,‘validateCtr’,‘validateCtr’,);

And the class file

<?php if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); class validateCtr { function validateCtr($bean, $event, $arguments){ if(!defined('sugarEntry'))define('sugarEntry', true); require_once('include/entryPoint.php'); $db = DBManagerFactory::getInstance(); $host_name = $db->connectOptions["db_host_name"]; $database_user_name = $db->connectOptions["db_user_name"]; $database_pass = $db->connectOptions["db_password"]; $database_name = $db->connectOptions["db_name"]; $link = mysql_connect($host_name,$database_user_name,$database_pass); if (!$link) {die('N\'a pas pu se connecter: ' . mysql_error());} mysql_select_db($database_name); //$ray = $bean->rayon; $rayon = $bean->p_rayon_p_contrat_1p_rayon_ida; $frn= $bean->p_fournisseur_p_contrat_1p_fournisseur_ida; $start_date=$bean->date_debut_contrat_c; $end_date=$bean->date_fin_contrat_c; //REQ = Parcours des contrats crées $sql_ctr = "SELECT * FROM `p_contrat` c, `p_contrat_cstm` cc, `p_fournisseur_p_contrat_1_c` fc , `p_rayon_p_contrat_1_c` rc WHERE c.id=cc.id_c AND cc.id_c=fc.p_fournisseur_p_contrat_1p_contrat_idb AND cc.id_c=rc.p_rayon_p_contrat_1p_contrat_idb AND rc.p_rayon_p_contrat_1p_rayon_ida='$rayon' AND fc.p_fournisseur_p_contrat_1p_fournisseur_ida='$frn' AND YEAR(cc.date_debut_contrat_c)=YEAR('$start_date') AND c.deleted=0"; $res_ctr = mysql_query($sql_ctr,$link); $num_of_record = mysql_num_rows($res_ctr); //echo ('-- NBR RECORD -- ('.$num_of_record.' ) '); /* if ( $num_of_record > 0 ){ SugarApplication::appendErrorMessage('Cet enregistrement est existant'); SugarApplication::redirect('index.php?module=P_Contrat&record='.$bean->id.'&action=DetailView'); Sugar_die(''); } } } ?>

but ,i think,the if statement is wrong,
seen that the error message is displayed each time, and the duplicate record is created, and in the list view I obteint a blank page