Adding an "older than x days" filter

Dear all,

I'm curious if any of you ever came across a customer needing to filter his records based on an "older than x days" condition and how you solved it? 

Typical example: Opportunities with close dates older than 7 days, last interaction older than 30 days etc. 

The operator would be used in list views, dashlets and reports. 

I've found the blog posts indicating how to build filters, but I suspect this will not work with reports. 

Maybe a calculated field that would flag the record? 

Parents Reply Children
  • Hi Cédric,

    Interesting approach, I had not thought about enriching the date time field. I'll check with the team!

    A bientôt !

    Damien Pochon

    CRM & Digital consultant @ ITS4U Group

  • Hi Damien Pochon,

    There is a new filter operators like "next x days" or "last x days" for Date field in our last project. That was done with custom logic for filter-rows view and custom fixForFilter method in overridden class CustomSugarFieldDatetime which based on the operator in filter will add certain where condition for SugarQuery.

    It will work in list and dashlets but not in reports though. 

    Let me know if you need details.

  • I've added exactly this filter myself, and one to get exactly N days ago.  Here is a step by step guide.

    Warning - this changes a couple of core files so you may need to make the changes again after any upgrade.

    1. First add the language string to the reports module.

    custom/extension/modules/Reports/ext/lang/en_us.lang.php

    $mod_strings['LBL_BEFORE_N_DAYS'] = 'Before last # Days';
    $mod_strings['LBL_N_DAYS_AGO'] = '# Days Ago';

    2. In modules/Reports/templates/templates_modules_def_js.php add these lines

    qualifiers[qualifiers.length] = {name:'tp_before_n_days',value:'<?php echo $mod_strings['LBL_BEFORE_N_DAYS']; ?>'};
    qualifiers[qualifiers.length] = {name:'tp_n_days_ago',value:'<?php echo $mod_strings['LBL_N_DAYS_AGO']; ?>'};

    3. Copy include/generic/SugarWidgets/SugarWidgetFielddatetime.php to custom/include/generic/SugarWidgets/SugarWidgetFielddatetime.php

    Add these 2 functions to your new file - custom/include/generic/SugarWidgets/SugarWidgetFielddatetime.php

    function queryFilterTP_before_n_days($layout_def)
    {
        $days = $layout_def['input_name0'] - 1;

        $begin = $this->now()->get("-10 years")->get_day_begin();
        $end = $this->now()->get("-$days days")->get_day_begin();

        return $this->get_start_end_date_filter($layout_def, $begin, $end);
    }

    function queryFilterTP_n_days_ago($layout_def)
    {
        $days = $layout_def['input_name0'];

        return $this->queryDay($layout_def, $this->now()->get("-$days day"));
    }

    4. Repair and rebuild.