suitecrm - 如何检查关系字段值正在变化
问题描述
我正在为 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();
}
}
}
}
推荐阅读
- sql-server - 将 100,000 行上传到 SQL Server 数据库
- matrix - Fortran中多线程矩阵的转置
- ios - 嵌入式框架的 Crashlytics 集成
- python - 输出不断重复
- java - JSCH -> 将 'my.host.com' (RSA) 永久添加到已知主机列表中(错误)
- sql - REGEXP_EXTRACT 数据工作室
- c++ - TC++PL 第 4 版,C++ {}-list 实现模型
- nestjs - 如何在 NestJS 的 TypeORM 中编写 setval()?
- php - Laravel:如何处理表单中的重复数据
- blackberry-playbook - 没有收到 Blackberry Playbook 代码签名密钥