2

I'm looking to make Quicksearch more usable for my users when it comes to searching for contacts of type Organization.

Specifically it would be great if they could use Quicksearch to find an Organization by its Nickname field.

Currently Quicksearch only seems to match on the organization's name (organization_name db field).

  1. Does the setting Search Preferences > Include Nickname only apply to Individual contacts and not Organization contacts?

  2. Is there any easy way to enable this via configuration that I'm overlooking?

Otherwise I can think of a quick workaround, which is for me to stuff the nick_name into the organization_name field.

2 Answers 2

3

There are 4 relevant fields to consider:

  1. Organization Name
  2. Nickname
  3. Display Name
  4. Sort Name

Fields 3 & 4 are readonly "calculated" fields, which by default in Civi are simply populated with the Organization Name (field 1). But they're not to be confused. The 4th is exclusively used in searching - that's the field used by quicksearch, not field 1.

Unfortunately there is no UI in CiviCRM for configuring this field for Organizations (for Individuals, yes, just not for Orgs). But a very simple hook would do it:

function hook_civicrm_post($op, $objectName, $objectID, $objectRef) {
  if ($objectName === 'Organization') {
    CRM_Core_DAO::executeQuery('UPDATE civicrm_contact
      SET sort_name = CONCAT(organization_name, " (", nick_name, ")")
      WHERE contact_type = "Organization" AND nick_name IS NOT NULL');
  }
}

It's slightly crude because it updates every org in the database every time one is saved, but that ensures things are always up-to-date. If you had millions of orgs in the db it might hurt performance, otherwise it's the simplest solution.

1
  • Good clarification on Sort Name. And thanks for the hook- that's precisely how I would plan to combine the organization name and nickname. Now, onto figuring out civix and packaging the hook...
    – Justin657
    Nov 28, 2023 at 16:31
2

The setting Search Preferences > Include Nickname, do work on a quick search for Organization but the result displayed will not contact nick name in it.

1
  • That's not what I'm seeing when I do a quicksearch. I have "Include Nickname"=Yes and in the db the organizations have, as @Coleman described, the sort_name field equal to the organization_name. When I do a quicksearch for one of the nicknames, nothing comes up. I can only find organizations when searching by the Organization name (Sort Name). I'm on Civi 5.67.1.
    – Justin657
    Nov 28, 2023 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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