Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-7516

Views filter handler doesn't work for multiple value custom fields

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Major
    • Resolution: Fixed/Completed
    • Affects Version/s: 3.3.3
    • Fix Version/s: 3.4.alpha
    • Labels:
      None

      Description

      I made a civicrm_contact view and put in a filter for a custom field called "organization categories." Some contacts have multiple categories, and these contacts were not showing up in the view. This was happening because the views query was trying to use the IN operator to compare a list of option values to the value of the custom field, and since the custom fields store multiple values as a delimited string, the comparison fails.

      I wrote a quick patch to solve this - it adds an op_simple() method to the civicrm_handler_filter_custom_option handler. It uses LIKE statements instead of IN to search through the custom field for occurrences of the target value surrounded, preceded or followed by the delimiter.

      The performance is not great because it creates three LIKES for each search value, but this cost may be unavoidable and may not be too different than what the IN operator does normally. The alternative is to move the main part of filter into the pre_render method where we could use PHP to remove results. This could perform a bit faster, but would be less abstract and more confusing.

      The attached patch has not been thoroughly tested (especially not with "not in" option) but works to solve the problem as I have encountered it.

        Attachments

          Activity

            People

            • Assignee:
              jalama Jim Taylor
              Reporter:
              dpolant Dan Polant
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: