add where clause for listview data in SugarCRM

sugarcrmdevelopers —  February 28, 2011

Editor’s Note: This post is republished with permission from the blog of Milos Miric, who is frequent poster in the Sugar forums. Here he addresses a question from a forums post asking about how to have a default filter on listviews.

 

Hey all, while reading the forum this question came up so here is a way how easily to do it and you can override it in custom folder also, so it will be upgrade safe way.

For the example we want for Accounts listview to show only accounts that name is like ‘htc’

We will create a file in Accounts/views/view.list.php and add the following code:

<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

require_once('include/MVC/View/views/view.list.php');

// name of class match module
class AccountsViewList extends ViewList{

	// where clause that will be inserted in sql query
	var $where = 'like 'htc'';
 	function AccountsViewList()
 	{
 		parent::ViewList();
 	}

 	/*
 	 * Override listViewProcess with addition to where clause to exclude project templates
 	 */
    function listViewProcess()
    {
            $this->lv->setup($this->seed, 'include/ListView/ListViewGeneric.tpl', $this->where, $this->params);
            echo $this->lv->display();
    }

}

?>

Share