Relate field not showing in audit log after saving through the logic hook in version 10.

Hi everyone,

I have a related field and saving it through the logic hook. After saving it is not showing in the audit log in version 10 and the field is selected with audit in the studio.

It works fine when we save it normally in the module but getting an issue with the logic hook.

Please suggest a solution.

Thanks

Laxmi Chand Saini

Parents Reply Children
  • Sorry, due to restrictions I couldn't share my logic.

  • Hi Laxmichand,

    I persoanlly have not tested this code, but can you just give a try whether it works for you or not.

    Step 1: Create a before save definition logic hook under custom/Extension/modules/Contacts/Ext/LogicHooks/logic_hooks.php

    <?php
    $hook_array['before_save'][] = Array(1, '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){
            // check for the change
            if($bean->fetched_rel_row['account_id'] != $bean->account_id){
                // prepare an array to audit the changes in parent module's audit table
                $aChange = array();
                $aChange['field_name'] = 'account_id';
                $aChange['data_type'] = 'relate';
                $aChange['before'] = $bean->fetched_rel_row['account_id'];
                $aChange['after'] = $bean->account_id;
                // save audit entry
                $bean->db->save_audit_records($bean, $aChange);
            }
        }
    }

    Step 3: Please perform the Quick Repair and Rebuild and check the code if it works or  not.

    Let me know how it goes for you :)