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

Hello.

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;

$parent_module_url=$bean->parent_type;

$query = <<<SQL

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

WHERE phone.parent_id='$hol_parent_id'

AND phone.main_ phone ='1'

AND phone.deleted='0'

GROUP BY phone.parent_id

SQL;

            $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,

'parent_id'=>$hol_parent_id,

'return_module'=>$parent_module_url,

'return_id'=>$hol_parent_id,

);

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

 

SugarApplication::redirect($url); 

}

}

}

 

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

How to stop saving?

 

Thank,

Artem Brat.

Outcomes