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
  • Hi,

    Yes, I have faced the same scenario in my project. Audit log record will create only on UI updates.

    So, I would like to suggest, add the logic for audit log record creation for relationship field in your logichook file.

    Hope this would help for you.

  • Hi Dhanalaskhmi

    Can you share your logic?

    laxmichand

  • 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 :)

  • Hi Poojitha,

    It is not working proper. $bean->fetched_rel_row['account_id'] alway getting empty.

    A new value showing in the audit but the old value is missing.

    laxmichand

  • Hi,

    Can you try with $bean->fetched_row['account_id'].

Reply Children
No Data