Thursday, February 25, 2016

SugarCRM - Audit relate fields


URL: http://urdhva-tech.blogspot.com/2013/02/audit-relate-fields.html

How to audit relate fields?

Step 1: Create a before save definition logic hook under custom/modules/Contacts/logic_hooks.php
<?php
$hook_array['before_save'][] = Array(90, 'Audit account name', 'custom/modules/Contacts/auditAcc.php','auditAccC', 'auditAccF');

Step 2: Create file auditAcc.php under custom/modules/Contacts folder and add following code.


<?php
class auditAccC {
    function auditAccF($bean) {
        if($bean->fetched_rel_row['account_id'] != $bean->account_id) {
            $aChange = array();
            $aChange['field_name'] = 'account_id';
            $aChange['data_type'] = 'relate';
            $aChange['before'] = $bean->fetched_rel_row['account_id'];
            $aChange['after'] = $bean->account_id;
            $bean->db->save_audit_records($bean, $aChange);
        }
    }
} 

No comments:

Post a Comment