Sugarcrm 在SuiteRM中,如何在关系表的子面板中添加自定义字段?
我有一个模块和一个子面板,另一个模块与其相关。 如下图所示- 在上图中,它是关系中模块的子面板, 我在数据库的关系表中添加了一列 我的要求是在这个子面板列表视图中添加该字段,如图中红色矩形所示,这在我所知的工作室中是不可能的。Sugarcrm 在SuiteRM中,如何在关系表的子面板中添加自定义字段?,sugarcrm,suitecrm,Sugarcrm,Suitecrm,我有一个模块和一个子面板,另一个模块与其相关。 如下图所示- 在上图中,它是关系中模块的子面板, 我在数据库的关系表中添加了一列 我的要求是在这个子面板列表视图中添加该字段,如图中红色矩形所示,这在我所知的工作室中是不可能的。 如果有人有这样的想法,请分享。在开发自定义SuiteRM模块的过程中,可能会出现这样的情况:在两个模块之间的关系表中存储额外数据会很方便。这在studio或module builder中是不可能的,即使对于有经验的程序员来说也不是那么简单,除非您对SuiteRM底层架构
如果有人有这样的想法,请分享。在开发自定义SuiteRM模块的过程中,可能会出现这样的情况:在两个模块之间的关系表中存储额外数据会很方便。这在studio或module builder中是不可能的,即使对于有经验的程序员来说也不是那么简单,除非您对SuiteRM底层架构有深入的了解 步骤1您需要做的第一件事是在关系的元数据中定义新字段。我将在自定义模块
FP\u事件
和联系人
之间的关系中添加该字段。关系fp\u events\u contacts
是一个many-to-many
,子面板将在fp\u events模块的contacts子面板中显示字段
此文件位于custom/metadata/fp\u events\u contactsMetaData.php
$app_strings['LBL_ACCEPT_CANCELLED'] = 'Date Cancelled';
在下面的代码中,请注意,我在字段数组中添加了一个名为date\u cancelled
的字段,类型为date
$dictionary["fp_events_contacts"] = array (
'true_relationship_type' => 'many-to-many',
'relationships' =>
array (
'fp_events_contacts' =>
array (
'lhs_module' => 'FP_events',
'lhs_table' => 'fp_events',
'lhs_key' => 'id',
'rhs_module' => 'Contacts',
'rhs_table' => 'contacts',
'rhs_key' => 'id',
'relationship_type' => 'many-to-many',
'join_table' => 'fp_events_contacts_c',
'join_key_lhs' => 'fp_events_contactsfp_events_ida',
'join_key_rhs' => 'fp_events_contactscontacts_idb',
),
),
'table' => 'fp_events_contacts_c',
'fields' =>
array (
0 =>
array (
'name' => 'id',
'type' => 'varchar',
'len' => 36,
),
1 =>
array (
'name' => 'date_modified',
'type' => 'datetime',
),
2 =>
array (
'name' => 'deleted',
'type' => 'bool',
'len' => '1',
'default' => '0',
'required' => true,
),
3 =>
array (
'name' => 'fp_events_contactsfp_events_ida',
'type' => 'varchar',
'len' => 36,
),
4 =>
array (
'name' => 'fp_events_contactscontacts_idb',
'type' => 'varchar',
'len' => 36,
),
5 =>
array (
'name' => 'invite_status',
'type' => 'varchar',
'len'=>'25',
'default'=>'Not Invited',
),
6 =>
array (
'name' => 'accept_status',
'type' => 'varchar',
'len'=>'25',
'default'=>'No Response',
),
7 =>
array (
'name' => 'email_responded',
'type' => 'int',
'len' => '2',
'default' => '0',
),
8 =>
array (
'name' => 'date_cancelled',
'type' => 'date',
),
),
'indices' =>
array (
0 =>
array (
'name' => 'fp_events_contactsspk',
'type' => 'primary',
'fields' =>
array (
0 => 'id',
),
),
1 =>
array (
'name' => 'fp_events_contacts_alt',
'type' => 'alternate_key',
'fields' =>
array (
0 => 'fp_events_contactsfp_events_ida',
1 => 'fp_events_contactscontacts_idb',
),
),
),
);
将所需字段添加到字段数组后,从SuiteRM的“管理”面板进行快速修复和重建,然后执行建议的SQL查询,这会将字段添加到关系的数据库表中。(我通过进入phpmyadmin
并查看fp\u events\u contacts\u c
表,再次检查字段是否已添加。)
步骤2您的字段现在已定义并在实际的数据库表中,但如果您希望字段实际显示在子面板中,则只需要一半。接下来要做的是在关系的vardefs
中定义新字段。这是通过在custom/Extensions文件夹中添加一个文件来实现的,如:custom/Extension/modules/Contacts/Ext/Vardefs/CAN\u ANY\u NAME.php
$app_strings['LBL_ACCEPT_CANCELLED'] = 'Date Cancelled';
在此文件中,为添加的每个字段添加以下三个定义。请注意,所有字段名和ID在定义之间都匹配,因为此处的小打字错误会阻止字段显示在子面板中,并且可能是最难发现的问题:
$dictionary['Contact']['fields']['e_date_cancelled'] =
array (
'name' => 'e_date_cancelled',
'rname' => 'id',
'relationship_fields'=>array('id' => 'cancelled_id', 'date_cancelled' => 'event_cancelled'),
'vname' => 'LBL_CONT_ACCEPT_CANCELLED',
'type' => 'relate',
'link' => 'fp_events_contacts',
'link_type' => 'relationship_info',
'join_link_name' => 'fp_events_contacts',
'source' => 'non-db',
'importable' => 'false',
'duplicate_merge'=> 'disabled',
'studio' => false,
);
$dictionary['Contact']['fields']['event_cancelled'] =
array(
'massupdate' => false,
'name' => 'event_cancelled',
'type' => 'date',
'studio' => 'false',
'source' => 'non-db',
'vname' => 'LBL_LIST_ACCEPT_CANCELLED',
'importable' => 'false',
);
$dictionary['Contact']['fields']['cancelled_id'] =
array(
'name' => 'cancelled_id',
'type' => 'varchar',
'source' => 'non-db',
'vname' => 'LBL_LIST_ACCEPT_CANCELLED',
'studio' => array('listview' => false),
);
步骤3您需要做的最后一件事是在子面板的实际布局定义中定义字段。在本例中,该文件位于:custom/modules/Contacts/metadata/subpanels/FP\u events\u subpanel\u FP\u events\u Contacts.php
$app_strings['LBL_ACCEPT_CANCELLED'] = 'Date Cancelled';
在下面的代码中,请注意,我将我的字段event\u cancelled
(定义见步骤2 vardefs)添加到list\u字段
数组中,并在数组中进一步添加e\u date\u cancelled
和cancelled\u id
,并将其用法标记为query\u only
$subpanel_layout['list_fields'] = array (
'name' =>
array (
'name' => 'name',
'vname' => 'LBL_LIST_NAME',
'sort_by' => 'last_name',
'sort_order' => 'asc',
'widget_class' => 'SubPanelDetailViewLink',
'module' => 'Contacts',
'width' => '23%',
'default' => true,
),
'account_name' =>
array (
'name' => 'account_name',
'module' => 'Accounts',
'target_record_key' => 'account_id',
'target_module' => 'Accounts',
'widget_class' => 'SubPanelDetailViewLink',
'vname' => 'LBL_LIST_ACCOUNT_NAME',
'width' => '22%',
'sortable' => false,
'default' => true,
),
'phone_work' =>
array (
'name' => 'phone_work',
'vname' => 'LBL_LIST_PHONE',
'width' => '15%',
'default' => true,
),
'email1' =>
array (
'name' => 'email1',
'vname' => 'LBL_LIST_EMAIL',
'widget_class' => 'SubPanelEmailLink',
'width' => '20%',
'sortable' => false,
'default' => true,
),
'event_status_name' =>
array (
'vname' => 'LBL_STATUS',
'width' => '10%',
'sortable' => false,
'default' => true,
),
'event_accept_status' =>
array (
'width' => '10%',
'sortable' => false,
'default' => true,
'vname' => 'LBL_ACCEPT_STATUS',
),
'event_cancelled' =>
array (
'width' => '10%',
'sortable' => false,
'default' => true,
'vname' => 'LBL_ACCEPT_CANCELLED',
),
'edit_button' =>
array (
'vname' => 'LBL_EDIT_BUTTON',
'widget_class' => 'SubPanelEditButton',
'module' => 'Contacts',
'width' => '5%',
'default' => true,
),
'remove_button' =>
array (
'vname' => 'LBL_REMOVE',
'widget_class' => 'SubPanelRemoveButton',
'module' => 'Contacts',
'width' => '5%',
'default' => true,
),
'e_accept_status_fields' =>
array (
'usage' => 'query_only',
),
'event_status_id' =>
array (
'usage' => 'query_only',
),
'e_invite_status_fields' =>
array (
'usage' => 'query_only',
),
'event_invite_id' =>
array (
'usage' => 'query_only',
),
'e_date_cancelled' =>
array (
'usage' => 'query_only',
),
'cancelled_id' =>
array (
'usage' => 'query_only',
),
'first_name' =>
array (
'name' => 'first_name',
'usage' => 'query_only',
),
'last_name' =>
array (
'name' => 'last_name',
'usage' => 'query_only',
),
'salutation' =>
array (
'name' => 'salutation',
'usage' => 'query_only',
),
'account_id' =>
array (
'usage' => 'query_only',
),
);
此外,请记住在这种情况下将标签添加到自定义语言字符串中
我把它添加到:custom/Extension/application/Ext/Language/en_us.Advanced OpenEvents.php
$app_strings['LBL_ACCEPT_CANCELLED'] = 'Date Cancelled';
但如果添加到mod字符串中,它可能会起作用
现在从管理面板进行另一次快速修复和重建,您的自定义关系字段现在应该显示在子面板上。现在,您可以通过查询或SuiteCRM bean framework将数据添加到模块控制器的这些字段中
注意:您可能必须手动进入数据库并向这些字段中添加一些虚拟数据,以确认它们是否显示(假设您尚未向新字段添加任何数据)
干杯 在SugarCRM中,您可以在Administration->Studio->ModuleName->Sub Panels->SubpanelName->将字段从右侧列表拖动到左侧列表中,然后save@Jay它不是模块的一个普通字段,它是两个模块关系表中的一个字段,所以直接不显示在studio模块子面板中进行拖放。哦,对不起,我的不好。虽然关系字段通常不是投射到模块中吗?例如,
product\u bundle\u product
关系的product\u index
被投影到modules/products/vardefs.php
中定义的产品中的position
字段中,使用'rel\u fields'=>数组('product\u index'=>数组('type'=>'integer')),
链接字段中的和'source=>'non db',非db整数字段“位置”中的“链接”=>“产品捆绑包”、“rname\U链接”=>“产品索引”
。至少在糖里是这样做的,不知道SuiteCRM。可能该字段设置为'studio
=>false,`虽然我想您可以尝试在studio中随机更改子面板并保存它。然后查找studio已将数据写入的文件(按修改日期搜索),并在运行快速修复和重建之前手动将字段添加到其中?如果该字段被投影到列出的模块中并且可以像这样使用,那么应该可以工作,否则您可能必须首先添加该投影。通常,使用Studio拖动滴水可用的所有字段,如果您的字段没有出现,您可能需要在custom/Extension/modules/Ext/Layoutdefs/my_custom_subpanel.php中创建一些代码