Answers.Body: <p>The setting Search Preferences &gt; Include Nickname, do work on a quick search for Organization but the result displayed will not contact nick name in it.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-11-28T16:43:59.527Z
Answers.Text: 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.
Answers.UserDisplayName: Justin657
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-11-28T12:14:15.183Z
Answers.LastActivityDate: 2023-11-28T12:14:15.183Z
Answers.UserDisplayName: Pradeep Nayak
Answers.Body: <p>There are 4 relevant fields to consider:</p>
  <ol>
  <li>Organization Name</li>
  <li>Nickname</li>
  <li>Display Name</li>
  <li>Sort Name</li>
  </ol>
  <p>Fields 3 &amp; 4 are readonly &quot;calculated&quot; 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.</p>
  <p>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:</p>
  <pre><code>function hook_civicrm_post($op, $objectName, $objectID, $objectRef) {
    if ($objectName === 'Organization') {
      CRM_Core_DAO::executeQuery('UPDATE civicrm_contact
        SET sort_name = CONCAT(organization_name, &quot; (&quot;, nick_name, &quot;)&quot;)
        WHERE contact_type = &quot;Organization&quot; AND nick_name IS NOT NULL');
    }
  }
  </code></pre>
  <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-11-28T16:31:35.040Z
Answers.Text: 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...
Answers.UserDisplayName: Justin657
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-11-28T01:00:29.017Z
Answers.LastActivityDate: 2023-11-28T12:32:19.407Z
Answers.LastEditDate: 2023-11-28T12:32:19.407Z
Answers.UserDisplayName: Coleman
Body: <p>I'm looking to make <strong>Quicksearch</strong> more usable for my users when it comes to searching for contacts of type <code>Organization</code>.</p>
  <p>Specifically it would be great if they could use Quicksearch to find an <code>Organization</code> by its <code>Nickname</code> field.</p>
  <p>Currently Quicksearch only seems to match on the organization's name (<code>organization_name</code> db field).</p>
  <ol>
  <li><p>Does the setting <code>Search Preferences &gt; Include Nickname</code> only apply to <code>Individual</code> contacts and not <code>Organization</code> contacts?</p>
  </li>
  <li><p>Is there any easy way to enable this via configuration that I'm overlooking?</p>
  </li>
  </ol>
  <p>Otherwise I can think of a quick workaround, which is for me to stuff the <code>nick_name</code> into the <code>organization_name</code> field.</p>
  
Tags: <organization><quicksearch>
Title: Quicksearch: include the Organization's Nickname
ThreadText: # Quicksearch: include the Organization's Nickname
  
  (Asked by: username_0 on 2023-11-27)
  
  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.
  
  **Tags:** organization, quicksearch
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2023-11-28. Score: 3 | Accepted answer
  
  There are 4 relevant fields to consider:
  
  Organization Name
  Nickname
  Display Name
  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.
  
  > **Comments:**
  > **username_0**: 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...  
  
  ---
  
  ### Answer by username_1 on 2023-11-28. Score: 0
  
  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.
  
  > **Comments:**
  > **username_0**: 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 @username_2 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.  
  
  ---
  
  