SugarCRM:从外部表读取数据

发布于 2024-12-08 18:51:28 字数 149 浏览 0 评论 0原文

我正在尝试在 SugarCRM 的自定义列表视图中显示非 Sugar 表中的数据。目前,我正在自定义 view.list.php 文件中运行 SQL 查询,但这显示的是列表下方的数据,而不是替换列表视图中的默认查询。

如何使用自定义 SQL 替换列表视图中的默认查询?

I'm trying to display data from a non-Sugar table in a custom listview in SugarCRM. Currently I'm running an SQL query in a custom view.list.php file, but this is displaying the data below the list rather than replacing the default query in the listview.

How can I replace the default query in a listview with custom SQL?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

等风来 2024-12-15 18:51:28

您不必经历所有这些。

当您在 ModuleBuilder 中创建自定义模块时。部署包
编辑 vardefs.php 和 Module_sugar.php 并将 table_name 更改为指向新表。然后,您实际上不必编写任何特殊代码,自定义字段将起作用并为您完成联接。

class CustomModule_sugar extends SugarBean {
var $table_name = 'external_table';

You don't have to go through all of that.

When you create a custom module in ModuleBuilder. Deploy the package
when edit the vardefs.php and Module_sugar.php and change the table_name to point to the new table. Then you don't actually have to write any special code and custom fields will work and complete the join for you.

class CustomModule_sugar extends SugarBean {
var $table_name = 'external_table';
骄兵必败 2024-12-15 18:51:28

我设法通过重写模块基类中的 create_new_list_query() 方法来解决这个问题:

class CustomModule extends CustomModule_sugar {

    function CustomModule(){    
        parent::CustomModule_sugar();
    }


    // this is the method which constructs the default SQL query
    function create_new_list_query($order_by, $where, $filter, $params, $show_deleted, $join_type, $return_array, $parentbean, $singleSelect){ 
        // call the parent method to populate all params - will cause errors/problems elsewhere otherwise
        $ret_array = parent::create_new_list_query($order_by, $where,$filter,$params, $show_deleted,$join_type, $return_array,$parentbean, $singleSelect); 

        // override module sql with custom query
        // alias external field names so they match the fields set up in Sugar
        $ret_array['select'] = 'SELECT primary_id as id, date_added as date_entered, field_name as name, external_notes as notes';
        $ret_array['from'] = ' FROM external_table';

        // update these with appropriate SQL
        $ret_array['where'] = '';
        $ret_array['order_by'] = '';

        return $ret_array; 
    }
}

此方法创建一个在 /includes/ListView/ListViewData.php 中使用的 SQL 语句。我已经为从外部表中选择的字段名称添加了别名,以匹配 Sugar 中设置的字段名称(比创建或重命名每个字段更容易)。

I've managed to solve this by overriding the create_new_list_query() method in the module base class:

class CustomModule extends CustomModule_sugar {

    function CustomModule(){    
        parent::CustomModule_sugar();
    }


    // this is the method which constructs the default SQL query
    function create_new_list_query($order_by, $where, $filter, $params, $show_deleted, $join_type, $return_array, $parentbean, $singleSelect){ 
        // call the parent method to populate all params - will cause errors/problems elsewhere otherwise
        $ret_array = parent::create_new_list_query($order_by, $where,$filter,$params, $show_deleted,$join_type, $return_array,$parentbean, $singleSelect); 

        // override module sql with custom query
        // alias external field names so they match the fields set up in Sugar
        $ret_array['select'] = 'SELECT primary_id as id, date_added as date_entered, field_name as name, external_notes as notes';
        $ret_array['from'] = ' FROM external_table';

        // update these with appropriate SQL
        $ret_array['where'] = '';
        $ret_array['order_by'] = '';

        return $ret_array; 
    }
}

This method creates an SQL statement which is used in /includes/ListView/ListViewData.php. I've aliased the field names selected from the external table to match the names of the fields set up in Sugar (easier than creating or renaming every single field).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文