1

I've fairly recently upgraded from 4.4 to 4.6.12 in Drupal. We have a custom date field that is Searchable and Search by Range is Yes. This used to work but doesn't now: The error includes this: No matches found for: Start date In '20 May 2, 20 July 2' ...AND... Searches for date fields not by range are OK.

I've just tried this in the 4.7 WordPress demo (UK locale) and can repeat the problem there, though the no matches error report format is better. search for specific date search in date range fails

The specific date case is handled in convertFormValues() in 4.6.12 CRM/Contact/BAO/Query.php - but not in 4.7.2.

Any suggestions for how to fix this?

Thanks, Chris

2

In 4.6.12 CRM/Contact/BAO/Query.php I've added this case in convertFormValues() to fix this - someone may do it more beautifully:

elseif (!empty($values) && is_array($values) && self::isCustomDateField($id)) {
    $from = FALSE;
    if (array_key_exists('from',$values)){
        $from = $values['from'];
        $from = CRM_Utils_Date::processDate($from);
    }
    $to = FALSE;
    if (array_key_exists('to',$values)){
        $to = $values['to'];
        $to = CRM_Utils_Date::processDate($to);
    }
    if( $from && $to){
        $q = array('BETWEEN' => array($from,$to));
    } else if ($from){
        $q = array('>=' => $from);
    } else if ($to){
        $q = array('<=' => $to);
    }
    $params[] = array($id, '=', $q, 0, $wildcard);
}

This handles the case when the custom field is a date but the supplied $values is not a single value, but is instead an array with from and/or to values.

  • Can we get a patch on this? This was hurting one charity I worked for. – JohnFF Mar 17 '16 at 18:39
  • I'm shortly away until Monday. If anyone can do the honours: the above code is inserted at line 1512 in the 4.6.14 code. – chriscant Mar 18 '16 at 17:04
  • @JohnFF Here's my patch for 4.6.14: link – chriscant Mar 23 '16 at 11:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.