如何检查关系字段值是否发生变化

How to check relationship field value is changing

我在 Suite crm 的历史模块工作。我的模块正在跟踪帐户和联系人之间关系变化的历史记录。我正在使用 Notes 模块来创造历史。

我的期望是在将关系合同添加到帐户后添加注释记录。

function addRelationshipHook($bean, $event, $arguments){
        if($arguments['related_module']=='Accounts'){
            if($bean->account_id != $bean->rel_fields_before_value['account_id'] ){
                $noteBean7 = BeanFactory::newBean('Notes');
                $noteBean7->name = "Premise created for Customer";
                $noteBean7->parent_type = "Contacts";
                $noteBean7->parent_id = $bean->id;
                $noteBean7->contact_id = $bean->id;
                $noteBean7->assigned_user_id = $bean->assigned_user_id;
                $noteBean7->save();
            }

        }

    }

$hook_array['before_relationship_add'][] = Array(78, 'addRelationshipHook', 'custom/modules/Contacts/ContactsLogicHook.php','ContactsLogicHook', 'addRelationshipHook'); 

当我在联系人编辑页面中更改关系时,它起作用了。但是当我在帐户中添加关系联系人时,它确实有效,函数被调用但是 $bean->account_id 是相同的 $bean->rel_fields_before_value['account_id'].

我指出了我的问题。检查 $bean->account_id 和 $arguments['related_id']。有效

    function addRelationshipHook($bean, $event, $arguments){
        if($arguments['related_module']=='Accounts'){
            if($bean->account_id != $bean->rel_fields_before_value['account_id'] ){
// when you update account on contact edit page
                $noteBean7 = BeanFactory::newBean('Notes');
                $noteBean7->name = "Premise created for Customer";
                $noteBean7->parent_type = "Contacts";
                $noteBean7->parent_id = $bean->id;
                $noteBean7->contact_id = $bean->id;
                $noteBean7->assigned_user_id = $bean->assigned_user_id;
                $noteBean7->save();
            }else{

                if($bean->account_id != $arguments['related_id'] ){
//when you add relationship contact to account
                    $noteBean7 = BeanFactory::newBean('Notes');
                    $noteBean7->name = "Premise created for Customer";
                    $noteBean7->parent_type = "Contacts";
                    $noteBean7->parent_id = $bean->id;
                    $noteBean7->contact_id = $bean->id;
                    $noteBean7->assigned_user_id = $bean->assigned_user_id;
                    $noteBean7->save();
                }
            }
        }

    }