AnsweredAssumed Answered

after_relationship_add is not working for first record creation in Subpanel.

Question asked by Anurag Tiwari on May 20, 2016

I have written code like find below but for first record creation into subpanel it is not get value.

 

logic_hook.php:

 

$hook_array['after_relationship_add'] = Array();

$hook_array['after_relationship_add'][] = Array(1 , 'ApplicationAmtCalculation' ,'custom/modules/Contacts/Update_Payment.php' ,'ProcessRecord' ,'ProcessRecord');

 

class and Function:

 

if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

class ProcessRecord{

  function ProcessRecord(&$bean,$event,$arguments)

  {

 

  global $db;

  $GLOBALS['log']->fatal($arguments['related_id']);

  $related_id = $arguments['related_id'];

  $record_id = $arguments['id'];

 

 

  $query_installment = "SELECT sum(amount) as Paid_amt FROM

  scrm_payments SP JOIN contacts_scrm_payments_1_c CP ON

  CP.contacts_scrm_payments_1scrm_payments_idb = SP.id and

  CP.contacts_scrm_payments_1contacts_ida='$record_id' and SP.deleted=0 ORDER BY SP.date_entered DESC LIMIT 0,1";

 

$GLOBALS['log']->fatal($query_installment);

  $result_installment = $db->query($query_installment);

  $row_installment = $db->fetchByAssoc($result_installment);

  $amount_paid = $row_installment['Paid_amt'];

 

 

  $update_query = "UPDATE contacts_cstm SET paid_amount_c='$amount_paid' where id_c='$record_id'";

  $GLOBALS['log']->fatal($update_query);

  $result_update_query = $db->query($update_query);

 

 

  //~ exit;

  }

 

}

 

Output in Log :

 

This is log record when First record is created:

Sat May 21 10:46:44 2016 [19738][1][FATAL] 1f955af8-e1b1-c1ff-f53c-573fef5f4d59

Sat May 21 10:46:44 2016 [19738][1][FATAL] SELECT sum(amount) as Paid_amt FROM

scrm_payments SP JOIN contacts_scrm_payments_1_c CP ON

CP.contacts_scrm_payments_1scrm_payments_idb = SP.id and

CP.contacts_scrm_payments_1contacts_ida='da32924d-2f09-6ce2-165c-573fef994644' and SP.deleted=0 ORDER BY SP.date_entered DESC LIMIT 0,1

Sat May 21 10:46:44 2016 [19738][1][FATAL] UPDATE contacts_cstm SET paid_amount_c='' where id_c='da32924d-2f09-6ce2-165c-573fef994644'

 

Note: Paid Amount is Empty.

 

This is log for second record creation

 

Sat May 21 10:47:31 2016 [19797][1][FATAL] 702984bb-4d6e-f270-4cf2-573fef43a998

Sat May 21 10:47:31 2016 [19797][1][FATAL] SELECT sum(amount) as Paid_amt FROM

scrm_payments SP JOIN contacts_scrm_payments_1_c CP ON

CP.contacts_scrm_payments_1scrm_payments_idb = SP.id and

CP.contacts_scrm_payments_1contacts_ida='da32924d-2f09-6ce2-165c-573fef994644' and SP.deleted=0 ORDER BY SP.date_entered DESC LIMIT 0,1

Sat May 21 10:47:31 2016 [19797][1][FATAL] UPDATE contacts_cstm SET paid_amount_c='1000' where id_c='da32924d-2f09-6ce2-165c-573fef994644'

 

Note: Paid amount is coming but only value of Second record is there current record value is not updating.

Outcomes