AnsweredAssumed Answered

How to update records with logic hook automatically?

Question asked by gaurav narula on Feb 1, 2018
Latest reply on Feb 1, 2018 by gaurav narula

Hello All

I am using SUGARCRM CE

I am creating a logic hook for accounts and cases. I have a field case_number_c in Accounts and field case_number in cases. I Created a Logic hook for updating the case_number_c whenever i add the case in the Cases but the only thing is that it is not updating the accounts detail view 'case_number_c' automatically... I need to click on edit and save to update the record.


here is my Code below for the Logic Hook


$hook_array['before_save'][] = Array(1, 'assignUser', 'custom/modules/Accounts/CaseNumber.php', 'UpdateRefund', 'updateAccount');



and the PHP file code is



class UpdateRefund {
function updateAccount(&$bean, $event, $arguments)
//Query ACCOUNTS table for assigned_user_id value of parent Account
$acct_id = $bean->id;
$query = "SELECT cases.case_number FROM cases ";
$query .= "WHERE cases.account_id = '$acct_id' LIMIT 1";
$results = $bean->db->query($query, true);
$row = $bean->db->fetchByAssoc($results);
$user_id = $row['case_number'];

//Change assigned_user_id value on Case
$bean->case_number_c = $user_id;



Please tell me how can i update it automatically so that once case is added the account should automatically update the case Number in the details view.


Thanks in advance