Hi. At this moment I am trying to make a functionality in SuiteCRM for the Account module, so when in a text field called NIT and save it, look in the database for that NIT code and show a message on the screen to the user saying that it already exists and redirects it to the creation page of an account, that is to say that it does not let it create the duplicate. However, in doing this I get the error that I show below. please if anyone knows how to fix this problem for me to function properly this function.
My code is the following:
/// ******************************************archivo ValidateDuplicateRecord.php **************************************************************//
class ValidateDuplicateRecord {
//Checks if the account name already exists
function validateDuplicateRecord( $bean, $event, $arguments ) {
$query_buscar_nombre = "SELECT COUNT(id) AS num FROM accounts WHERE name = '$bean->name'";
$v_sql_bean = $bean->db->query($query_buscar_nombre,true);
$row_beanrad = $bean->db->fetchByAssoc($v_sql_bean);
$nombre_encontrado = $row_beanrad['num'];
//Validar Si nombre Existe
if($nombre_encontrado > 0)
{
SugarApplication :: appendErrorMessage ("<strong><font size='6'>el registro no se puede guardar !!!.</font></strong>");
$ params = array (
'module' => 'Accounts',
'action' => 'EditView',
'record' => $bean-> id
);
SugarApplication :: redirect (‘index.php?’. Http_build_query ($ params). ‘& Return_module = Accounts & return_action = EditView & offset = 1’);
}
}
}
////////////////////////////////////// fin del código ///////////////////////////////////////////////////////////
Pero al momento de crear un registro de cuenta nueva ingresando un nombre que no existe me sale este una vista de texto con los siguiente:
class ValidateDuplicateRecord { //Checks if the account name already exists function validateDuplicateRecord( $bean, $event, $arguments ) { $query_buscar_nombre = “SELECT COUNT(id) AS num FROM accounts WHERE name = ‘$bean->name’ AND deleted = 0”; $v_sql_bean = $bean->db->query($query_buscar_nombre,true); $row_beanrad = $bean->db->fetchByAssoc($v_sql_bean); $nombre_encontrado = $row_beanrad[‘num’]; //Validar Si nombre Existe if($nombre_encontrado > 0) { SugarApplication::appendErrorMessage(’
Record saved successfully!
‘); exit; //SugarApplication :: appendErrorMessage (“el registro no se puede guardar !!!.”);� ����������������//$params = array (� �����������������//�’module’ => ‘Accounts’,� ����������������//��’action’ => ‘EditView’,� �����������������//��’record’ => $bean-> id� ���������������//�);� ��������//SugarApplication :: redirect (‘index.php?’. Http_build_query ($params). ‘& Return_module = Accounts & return_action = EditView & offset = 1’); } } function methodMayusBSHook($bean, $event, $arguments) { $bean->name=strtoupper($bean->name); } }
/////// por favor si alguien que pueda ayudarme a corregir el error y lograr que funcione lo que pretendo hacer. Gracias. /////////////////////////