首页 > 解决方案 > 如何检查关系字段值正在变化

问题描述

我正在为 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'] 相同。

标签: suitecrm

解决方案


我指出我的问题。检查 $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();
                }
            }
        }

    }

推荐阅读