I am currently running tests with CiviCRM 4.6.14 and have custom functionality working as we require. During testing by the end user, an issue has come to light with the 'Postcode' field.

Despite having the UK localization installed, the report filters are still treating the postcode field as an integer. UK postcodes are a mixture of letter and numbers and I need to be able to query the database using these.
Have I missed something in the localization? Is there something I can alter so the postcode field is interrogated as an alphanumeric rather than integer?

Any help would be appreciated. Many thanks Russell

  • Could you please specify what platform you are using (Wordpress, Drupal etc) and how did you import your contacts? – peterb Apr 23 '16 at 20:35
  • I have CiviCRM installed on Windows IIS installation with Wordpress as the CMS. All contacts address details are added manually at moment while I am testing – Russell Apr 28 '16 at 13:03

Short answer:

This is a limitation/bug in CiviCRM. The advanced search handles postcodes correctly (ex: I can search postcode ranges H4 to H5), but most reports do not. It would be a feature that needs to be implemented in CiviCRM reports.

Longer answer, if you are a developer:

We could fix it by changing the filter type in the report, but then US-style postal code would lose the ability to search by range. I'm not too sure how to implement that in the report.

Ex: civicrm/CRM/Report/Form.php in function addAddressFields():

    'postal_code' => array(
      'title' => ts('Postal Code'),
      'type' => 1,
      'name' => 'postal_code',

Should be:

    'postal_code' => array(
      'title' => ts('Postal Code'),
      'type' => CRM_Utils_Type::T_STRING,
      'name' => 'postal_code',

but, as I mentioned, this breaks "search postcode between X and Y". The advanced search has a checkbox to enable "search by range", and it works for UK/Canada-style postcodes, but I'm not sure how to implement this for reports.

  • Why can't we search between x and y if it's a string type? Seems like we should be able to - perhaps that's where the effort should go? In any case, US postal codes are not really numbers either (some start with '0', and then there's that suffix bit sometimes), so I think you have identified a bug that should be fixed ... [hehe, and I'm also from Canada ...] – Alan Dixon Apr 26 '16 at 20:46
  • @AlanDixon : we should add an option similar to the one in advanced search. The filter "between X and Y" works in the report is because CiviCRM implements that only for "Integer" filters. I'm not sure what's the best solution: implement "between X and Y" for strings? (it would show up everywhere, might be confusing), or add a new filter "Postal Code range" with custom handling? – bgm Apr 27 '16 at 15:18
  • Thanks for the advice on this. I'll give the code you suggest a run and assess with my users which option they feel would be most beneficial. Better handling of the Postcode string would be useful, although I'm not sure what the best solution would be. Has anyone tested the postcode functionality in 4.7 to see if there is any improvement? I have other issues preventing me looking at 4.7 at the moment – Russell Apr 28 '16 at 13:08
  • @bgm - good point, and yes a specific postal code range handling filter makes sense, especially because there may be some locales that need special treatment (e.g. removal of spaces, etc.). – Alan Dixon May 2 '16 at 15:16

Although you have the localisation file installed, do you have the setting in Administer/localization/address settings/Default Country actually set to United Kingdom? I do have it set up like this and it works for me by allowing UK post codes to be entered alpha/numerically. I am using civicrm 4.7.6 with Wordpress 4.5.1 Incidentally, I did not install the localisation file and haven't found a need for it, yet.

  • Yes, the default country is set to UK. The issue isn't with entering the UK postcode in to a contact, this works fine, but the utilisation of reporting by postcode. When you attempt to set a report filter based on a UK postcode, the report only accepts integer postcodes, i.e. US. Entering an alphanumeric postcode returns an error of incorrect data in the field. For the moment I think I will be advising users to generate the report the require, without the postcode filter and then export to CSV. Excel can then be used to filter by postcode and obtain the required information. – Russell May 3 '16 at 7:16

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.