【问题标题】:In SuiteCRM how to add custom field in sub panel from relationship table?在 SuiteCRM 中,如何在关系表的子面板中添加自定义字段?
【发布时间】:2019-09-05 09:34:41
【问题描述】:

我有一个模块和一个与另一个模块相关的子面板。 如下图-

在上图中,它是关系中模块的子面板, 我在数据库的关系表中添加了一列。

我的要求是在此子面板列表视图中添加该字段,如红色矩形中的图像所示,据我所知,这在工作室理想情况下是不可能的。 如果有人有想法做这样的事情,请分享。

【问题讨论】:

  • 在 SugarCRM 中,您可以在 Administration -> Studio -> ModuleName -> Sub-Panels -> SubpanelName -> 从右侧拖动字段列表进入左侧列表并保存
  • @Jay 不是模块的普通字段,是两个模块关系表中的一个字段,所以直接不显示in-studio模块子面板拖拽。
  • 哦,对不起,我的错。尽管通常不将关系字段投影到模块中吗?例如。关系product_bundle_productproduct_index 在链接字段中使用'rel_fields' => array('product_index' => array('type' => 'integer')), 和非db 整数字段“位置”中的'source' => 'non-db', 'link' => 'product_bundles', 'rname_link' => 'product_index', 投影到modules/Products/vardefs.php 中定义的产品中的字段position。至少在 Sugar 中是这样的,不知道 SuiteCRM。可能该字段设置为'studio => false,尽管
  • 我想你总是可以尝试随机更改工作室中的子面板并保存它。然后找到哪个文件工作室已将该数据写入(按修改日期搜索)并在运行快速修复和重建之前手动添加您的字段?如果该字段被投影到列出的模块中并且可以像这样使用,则应该可以工作,否则您可能必须先添加该投影。
  • 通常所有可用于使用 Studio 进行拖放的字段,如果您的字段没有出现,您可能需要在 custom/Extension/modules/Ext/Layoutdefs/my_custom_subpanel.php 中创建一些代码

标签: sugarcrm suitecrm


【解决方案1】:

在开发自定义 SuiteCRM 模块时,可能会在两个模块之间的关系表中方便地存储额外数据。这在工作室或模块构建器中是不可能的,即使对于经验丰富的编码人员来说也不是那么简单,除非您对 SuiteCRM 底层架构有深入的了解。

第 1 步 您需要做的第一件事是在关系的元数据中定义新字段。我将在自定义模块FP_eventsContacts 之间的关系中添加该字段。关系fp_events_contactsmany to many,子面板将在 FP_events 模块的联系人子面板中显示该字段。

这个文件可以在custom/metadata/fp_events_contactsMetaData.php找到

请注意,在下面的代码中,我在字段数组中添加了一个名为 date_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',
 ),
 ),
 ),
);

将所需字段添加到字段数组后,请从 SuiteCRM 的管理面板进行快速修复和重建,然后执行建议的 SQL 查询,这会将字段添加到关系的数据库表中。 (我通过进入phpmyadmin 并查看fp_events_contacts_c 表仔细检查了这些字段是否已添加。)

第 2 步 您的字段现在已定义并在实际的数据库表中,但如果您希望您的字段实际显示在子面板中,那么您的字段只有一半。您要做的下一件事是在vardefs 中为关系定义新字段。这是通过在 custom/Extensions 文件夹中添加一个文件来完成的,如下所示:custom/Extension/modules/Contacts/Ext/Vardefs/CAN_BE_ANY_NAME.php

在此文件中,为您添加的每个字段添加以下三个定义。请注意,定义之间的所有字段名称和 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_events_subpanel_fp_events_contacts.php

在下面的代码中,请注意我将我的字段 event_cancelled(在步骤 2 vardefs 中定义)添加到 list_fields 数组,并在数组的更下方添加 e_date_cancelledcancelled_id 并标记它们的用法作为query_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',
 ),
);

另外,请记住在这种情况下将标签 LBL_ACCEPT_CANCELLED 添加到自定义语言字符串中。

我添加到:custom/Extension/application/Ext/Language/en_us.Advanced OpenEvents.php

$app_strings['LBL_ACCEPT_CANCELLED'] = 'Date Cancelled';

但如果添加到 mod 字符串中,它可能会起作用。

现在从管理面板进行另一次快速修复和重建,您的自定义关系字段现在应该显示在子面板上。您现在可以通过查询或通过 SuiteCRM bean 框架将数据添加到模块控制器中的这些字段中。

请注意,您可能必须手动进入数据库并将一些虚拟数据添加到这些字段中以确认它们正在显示(假设您尚未向新字段添加任何数据)。

干杯!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-21
    • 1970-01-01
    • 2022-01-06
    • 1970-01-01
    相关资源
    最近更新 更多