我试图在SugarCRM的自定义列表视图中显示非Sugar表中的数据。目前,我正在自定义view.list.php文件中运行SQL查询,但这是在列表下方显示数据,而不是替换listview中的默认查询。SugarCRM:从外部表读取数据
如何用自定义SQL替换列表视图中的默认查询?
我试图在SugarCRM的自定义列表视图中显示非Sugar表中的数据。目前,我正在自定义view.list.php文件中运行SQL查询,但这是在列表下方显示数据,而不是替换listview中的默认查询。SugarCRM:从外部表读取数据
如何用自定义SQL替换列表视图中的默认查询?
我已经设法通过在模块基类重写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中设置的字段名称相匹配(比创建或重命名每个字段更容易)。
你不必经历所有这些。
在ModuleBuilder中创建自定义模块时。编辑vardefs.php和Module_sugar.php时,部署程序包 ,并将table_name更改为指向新表。然后,您实际上不必编写任何特殊的代码,并且自定义字段将起作用并为您完成联接。
class CustomModule_sugar extends SugarBean {
var $table_name = 'external_table';
您能解释一下,您在哪些文件中进行了更改以使其正常工作。 – user3286692