Search code examples
sugarcrmsuitecrm

Show records where a field is NULL inside the pop-up window


I was able to filter records that appear when we click on the select button inside a subpanel. It can be done by overriding the $initial_filter value like so:

public function display($widget_data, $additionalFormFields = null, $nonbutton = false) {
    global $app_strings; $initial_filter = '';
    $initial_filter.='&SOME_FIELD='.urlencode("SOMEVALUE");
}

That initial filter will be used as the $_GET parameter when the pop-up opens up so it will know which records to show

Now the tricky part is i’m trying to figure out how to filter it so it shows records where SOME_FIELD is empty… I tried something like SOME_FIELD=null or SOME_FIELD=false but it doesn’t work… If anyone can suggest anything it would be appreciated.


Solution

  • You will need to modify the list view query and data fetching logic. View following details for further help:

    For list view only: custom/modules/MODULE_NAME/views/view.list.php

    and following is the helping code:

    require_once('include/MVC/View/views/view.list.php');
    class MODULE_NAMEViewList extends ViewList {
    
        function listViewProcess() {
            global $current_user;
            $this->params['custom_where'] = ' AND module_name.name = "test" ';
    
            parent::listViewProcess();
    }
    
    }
    



    For list and popup view(both):

    You need to change the logic inside create_new_list_query function which actually prepares a query. Some modules have override it a bean level(e.g. see modules/Leads/Lead.php).

    If you want to override it in upgrade safe manner then create a file in custom directory e.g: custom/modules/Leads/Lead.php, then extend it from the core bean class like following:

    <?php
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
    
    require_once('modules/Leads/Lead.php');
    class CustomLead extends Lead {
    
        function create_new_list_query($order_by, $where,$filter=array(),$params=array(), $show_deleted = 0,$join_type='', $return_array = false,$parentbean=null, $singleSelect = false, $ifListForExport = false)
        { 
            // Code from create_new_list_query in and then modify it accordingly. 
        }
    }
    

    Register new bean class in this location: custom/Extension/application/Ext/Include/custom_leads_class.php and registration code will look like following:

    <?php
    $objectList['Leads'] = 'Lead';
    $beanList['Leads'] = 'CustomLead';
    $beanFiles['CustomLead'] = 'custom/modules/Leads/Lead.php';
    ?>