SuiteCRM 8.4.1:自定义Contact字段关联Cases模块及子面板显示方法
SuiteCRM 8.4.1 自定义字段关联Contacts并在Cases子面板显示解决方案
1. 确保自定义字段为正确的关联类型
如果你的"Contact"自定义字段是普通文本/数值字段,需要先将其改为关联字段(关联到Contacts模块):
- 进入后台Studio → Cases模块 → Fields
- 找到该自定义字段,修改字段类型为
Relate,关联模块选择Contacts - 系统会自动生成对应ID字段(如
custom_contact_id)和名称字段(如custom_contact_name),保存配置。
2. 配置自定义子面板显示关联联系人
2.1 编写子面板元数据
在custom/modules/Cases/metadata/subpanels/目录下创建custom_contacts_subpanel.php,定义子面板的过滤规则和显示字段:
<?php $subpanel_layout = [ 'top_buttons' => [], // 过滤条件:仅显示当前Cases自定义字段关联的联系人 'where' => "contacts.id = '{$bean->custom_contact_id}'", 'list_fields' => [ 'name' => [ 'vname' => 'LBL_NAME', 'widget_class' => 'SubPanelDetailViewLink', 'width' => '45%', ], 'email1' => [ 'vname' => 'LBL_EMAIL', 'width' => '35%', ], 'phone_work' => [ 'vname' => 'LBL_PHONE_WORK', 'width' => '20%', ], ], ];
2.2 将子面板添加到Cases详情页
修改custom/modules/Cases/metadata/recordviewdefs.php,在面板配置中加入自定义子面板:
<?php $layout_defs['Cases']['recordview']['panels'] = [ // 保留原有面板配置,新增以下面板 'LBL_CUSTOM_CONTACTS_PANEL' => [ 'columns' => 1, 'labelsOnTop' => true, 'placeholders' => true, 'subpanels' => [ 'custom_contacts_subpanel' => [ 'order' => 10, 'module' => 'Contacts', 'subpanel_name' => 'default', 'get_subpanel_data' => 'custom_contacts_subpanel', 'add_subpanel_data' => 'custom_contact_id', 'title_key' => 'LBL_CUSTOM_CONTACTS_SUBPANEL_TITLE', ], ], ], ];
2.3 添加语言包支持
在custom/modules/Cases/language/en_us.lang.php中添加子面板标题(根据实际使用语言调整):
<?php $mod_strings['LBL_CUSTOM_CONTACTS_SUBPANEL_TITLE'] = '关联联系人'; $mod_strings['LBL_CUSTOM_CONTACTS_PANEL'] = '联系人信息';
3. 实现选择联系人后自动刷新子面板
在custom/modules/Cases/clients/base/views/record/record.js中添加前端逻辑,当自定义字段值变化时刷新子面板:
({ extendsFrom: 'RecordView', initialize: function(options) { this._super('initialize', [options]); this.context.on('edit:custom_contact_id:fire', this.refreshCustomContactSubpanel, this); }, refreshCustomContactSubpanel: function() { const subpanel = this.$('.subpanel[data-subpanel-name="custom_contacts_subpanel"]'); if (subpanel.length) { subpanel.find('.refreshSubpanel').trigger('click'); } } })
4. 清除缓存并验证
- 进入后台管理员 → 管理员 → 清除缓存
- 打开任意Cases记录,选择自定义字段的联系人,检查子面板是否正常显示该联系人信息
内容的提问来源于stack exchange,提问作者DEV H GOWDA
相关产品推荐
相关产品推荐

