Artem Brat

How to stop saving in logic_hooks before_save

Discussion created by Artem Brat on Jul 19, 2017
Latest reply on Jul 20, 2017 by Artem Brat


I created a new module.

When you save, the condition is checked. If the condition is not met, then the message: “Message to the user”.


Use logic_hooks before_save.


class logic_hooks_tel_main_count


   function before_save_metod($bean, $event, $arguments)


$hol_parent_id = $bean->parent_id;

$tel_id = $bean->id;

$mt = $bean->main_ phone;


$query = <<<SQL

SELECT count(phone.parent_id) as counttel FROM phone INNER JOIN holdings ON

WHERE phone.parent_id='$hol_parent_id'

AND phone.main_ phone ='1'

AND phone.deleted='0'

GROUP BY phone.parent_id


            $results = $bean->db->query($query, true);

$row = $bean->db->fetchByAssoc($results);

$ct = $row['counttel']; 


if (condition “ct”)


                        SugarApplication::appendErrorMessage("{“Message to the user”.}");


$urlParameters = array( 

'module' => "phone", 

'action' => "EditView",

'record' => $tel_id, 

'parent_module' =>$parent_module_url,





$url = 'index.php?' . http_build_query($urlParameters); 







The SugarApplication :: redirect ($ url) method reloads the page. This method is not suitable.

How to stop saving?



Artem Brat.