Answers.Body: <p>I needed to do something similar. There were two things to work on: getting the Contact ID in the search suggestion in the quick search and getting CiviCRM to search the Contact Id by default when placing a number in the quick/regular search and hitting enter. </p>
  
  <p><em>Note: I just adapted my code to work with contact ID, didn't test it.</em></p>
  
  <p>I used a CiviCRM extension with the queryObjects hook:</p>
  
  <p><strong>[myext]/myext.php</strong></p>
  
  <pre><code>// Get the Contact ID to display in the suggestions
  function extname_civicrm_apiWrappers(&amp;$wrappers, $apiRequest) {
     if ($apiRequest['entity'] == 'Contact') {
        if ($apiRequest['action'] == 'getquick') {
            $wrappers[] = new CRM_Extname_APIWrapper_GetQuick();
        } 
    }
  }
  
  function emulate_civicrm_api3_contact_getList($params) {
  
      $res = civicrm_api3('Contact','get', $params);
  
      // reformat the output to look like getquick
      foreach ($res['values'] as $idx =&gt; &amp;$value) {
          $value['data'] = $value['id'].' :: '.$value['sort_name'] . ( empty($value['nick_name']) ? '' : ' ('.$value['nick_name'].')' );
          foreach (['street_address','city','state_province_name','postal_code','phone','email'] as $col) {
              if (!empty($value[$col])) $value['data'] .= ' :: '.$value[$col];
          }
      }
  
      return $res;
  }
  
  // Get the id to be part of the default search
  function extname_civicrm_queryObjects (&amp;$queryObjects, $type = 'Contact') {
      if ($type == 'Contact') {
          $queryObjects[] = new CRM_Extname_BAO_Query();
      }
  }
  </code></pre>
  
  <p><strong>[myext]/CRM/Extname/APIWrapper/GetQuick.php</strong>
  clas</p>
  
  <pre><code>s CRM_Extname_APIWrapper_GetQuick implements API_Wrapper {
  
    public function fromApiInput($apiRequest) {
  
          if (!empty($apiRequest['params']['field_name'])) return $apiRequest;
  
          $apiRequest['entity'] = 'Contact';
          $apiRequest['action'] = 'getlist';
          $apiRequest['function'] = 'emulate_civicrm_api3_contact_getList';
  
          $apiRequest['params']['sequential'] = '1';
          $apiRequest['params']['nick_name'] = $apiRequest['params']['id'] = $apiRequest['params']['name'];
  
          unset($apiRequest['params']['name']);
          unset($apiRequest['params']['option']);
          unset($apiRequest['params']['task']);
          unset($apiRequest['params']['field_name']);
          unset($apiRequest['params']['table_name']);
  
          return $apiRequest;
    }
  
    // this never seems called
    public function toApiOutput($apiRequest, $result) {
  
        return $result;
    }
  
  }
  </code></pre>
  
  <p><strong>[myext]/CRM/Extname/BAO/Query.php</strong></p>
  
  <pre><code>class CRM_Extname_BAO_Query extends CRM_Contact_BAO_Query_Interface {
  
      function &amp;getFields() {
          return ['id'];
      }
  
      function from($name, $mode, $side) {
          return '';
      }
  
      function where(&amp;$query) {
  
          $grouping = NULL;
          foreach (array_keys($query-&gt;_params) as $id) {
              if (empty($query-&gt;_params[$id][0])) {
                  continue;
              }
  
              $this-&gt;whereClauseSingle($query-&gt;_params[$id], $query);         
          }
  
      }
  
      function whereClauseSingle(&amp;$values, &amp;$query) {
          list($name, $op, $value, $grouping, $wildcard) = $values;
  
          $fields = $this-&gt;getFields();
          if (!empty($value) &amp;&amp; !is_array($value)) {
            $quoteValue = "\"$value\"";
          }
  
          // Look in CRM_Contact_BAO_Query:2025 for how this is all gatherered into or's and ands
  
          switch ($name) {
            case 'sort_name': 
              // the default search is grouping=0; this is pretty hard coded into CRM_Contact_BAO_Query
              if ($grouping==0) {
                  foreach ($query-&gt;_where[$grouping] as $key =&gt; $val) {
                      if (strpos($query-&gt;_where[$grouping][$key],'sort_name')===false) continue;
                      // search id if numeric
                      if (is_numeric($value)) {
                          $query-&gt;_qill[$grouping][$key] .= ' Or '.($value ? ts('Contact ID is '.$quoteValue) : ts('Contact ID is not '.$quoteValue));
                          $query-&gt;_where[$grouping][$key] .= ' OR '.CRM_Contact_BAO_Query::buildClause("contact_a.id", "=", (int)$value, "Int");
                      }
                      break;
                  }
              }
              return;
          }
  
  
      }
  
      public function getPanesMapper(&amp;$panes) {
  
          return $panes;
      }
  
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-11T06:35:09.713Z
Answers.Text: David, i don't follow "getting the Contact ID in the search suggestion in the quick search" since civi already provides this. guess i am misunderstanding something in your answer that a tweak might help
Answers.UserDisplayName: petednz - fuzion
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-11T17:08:32.620Z
Answers.Text: I didn't see contact id on the search preference. Is there another location to turn it on to display on the quick search suggestions?
Answers.UserDisplayName: David Hayes
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-11T21:20:20.440Z
Answers.Text: what version civi you on?
Answers.UserDisplayName: petednz - fuzion
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-11T21:22:17.383Z
Answers.Text: You should be seeing what is in screenshot here https://docs.civicrm.org/user/en/4.6/the-user-interface/searching/
Answers.UserDisplayName: petednz - fuzion
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-11T22:11:00.173Z
Answers.Text: 4.7.x 
  
  The code above would put the contact id in the quick search box suggestions here: http://imgur.com/a/tOWmz 
  
  The other part makes it search the contact id by default when adding the contact ID to that box.
Answers.UserDisplayName: David Hayes
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-12T00:04:47.640Z
Answers.Text: sorry David, I was mis-reading 'in' to mean, as a selector, not as an 'output'. crossed wires. so yours is effectively adding 'contact id' as an option to what is already offered at civicrm/admin/setting/search?reset=1
Answers.UserDisplayName: petednz - fuzion
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-08-12T05:45:41.130Z
Answers.Text: Will this Extension add Search by Contact ID to the New Contribution input screen? https://drive.google.com/file/d/0B774H5vmdPHQNVdXZ3N3MkNyM2s/view?usp=sharing
Answers.UserDisplayName: Iowa Boy
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-08-12T19:48:25.040Z
Answers.Text: While I am not 100% sure Carl, I believe it would. I have been using it to modify the results that are returned via the API. That selector uses the API.
Answers.UserDisplayName: David Hayes
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-10T23:19:48.337Z
Answers.LastActivityDate: 2017-04-10T23:19:48.337Z
Answers.UserDisplayName: David Hayes
Answers.Body: <p>It helps if you mention the version you are on. In the Quick Search you should be able to see a setting when you click in there, to use Internal ID, then you can just enter the ID.</p>
  
  <p>Personally I would make it even simpler if you have been sent a spreadsheet, or can get their data in a spreadsheet, and use the CONCATENATE function in your spreadsheet so you have a link from there to go directly to a link this this civicrm/contact/view/contribution?reset=1&amp;action=add&amp;cid=XXX&amp;context=contribution where XXX is the Internal ID</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-26T19:46:01.533Z
Answers.LastActivityDate: 2017-02-26T19:46:01.533Z
Answers.UserDisplayName: petednz - fuzion
Answers.Body: <p>You can add the contributions using Contact ID via the Import interface. Create a csv file with the contribution info and import it. </p>
  
  <p>But for the long term, I think this would be a brilliant addition to the New Contribution > Select Contact or Batch Entry > Select Contact search parameters. When people mail a check, our paper receipts have a tear off portion at that bottom that they can use with their next contribution. We could have it print their Contact ID in that lower section and use it when doing the data entry just as Doug described and it should save on selecting the wrong donor with a similar name (or we have some with the same name).</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-10T01:20:00.673Z
Answers.LastActivityDate: 2017-03-10T01:29:03.937Z
Answers.LastEditDate: 2017-03-10T01:29:03.937Z
Answers.UserDisplayName: Iowa Boy
Body: <p>I'm working with a direct mail company on a donation campaign. They plan on including the contact ID on the top of the donation tear off. Then when we manually enter the donation we're be able to search by contact ID, avoiding possible duplicates. This is the way they always do it for efficiency.</p>
  <p>There's several you can already add under &quot;Search Preferences&quot; but not the contact ID.</p>
  <p>Is it possible to just manually add it to the database?</p>
  <h1>morekidsonbikes</h1>
  
Tags: <contributions><search>
Title: Autocomplete Contact Search - Add Contact ID possible?
ThreadText: # Autocomplete Contact Search - Add Contact ID possible?
  
  (Asked by: username_0 on 2017-02-26)
  
  I'm working with a direct mail company on a donation campaign. They plan on including the contact ID on the top of the donation tear off. Then when we manually enter the donation we're be able to search by contact ID, avoiding possible duplicates. This is the way they always do it for efficiency.
  
  There's several you can already add under "Search Preferences" but not the contact ID.
  
  Is it possible to just manually add it to the database?
  
  # morekidsonbikes
  
  **Tags:** contributions, search
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_1 on 2017-04-10. Score: 1
  
  I needed to do something similar. There were two things to work on: getting the Contact ID in the search suggestion in the quick search and getting CiviCRM to search the Contact Id by default when placing a number in the quick/regular search and hitting enter.
  
  *Note: I just adapted my code to work with contact ID, didn't test it.*
  
  I used a CiviCRM extension with the queryObjects hook:
  
  **[myext]/myext.php**
  
  ```
  // Get the Contact ID to display in the suggestions
  function extname_civicrm_apiWrappers(&$wrappers, $apiRequest) {
     if ($apiRequest['entity'] == 'Contact') {
        if ($apiRequest['action'] == 'getquick') {
            $wrappers[] = new CRM_Extname_APIWrapper_GetQuick();
        } 
    }
  }
  
  function emulate_civicrm_api3_contact_getList($params) {
  
      $res = civicrm_api3('Contact','get', $params);
  
      // reformat the output to look like getquick
      foreach ($res['values'] as $idx => &$value) {
          $value['data'] = $value['id'].' :: '.$value['sort_name'] . ( empty($value['nick_name']) ? '' : ' ('.$value['nick_name'].')' );
          foreach (['street_address','city','state_province_name','postal_code','phone','email'] as $col) {
              if (!empty($value[$col])) $value['data'] .= ' :: '.$value[$col];
          }
      }
  
      return $res;
  }
  
  // Get the id to be part of the default search
  function extname_civicrm_queryObjects (&$queryObjects, $type = 'Contact') {
      if ($type == 'Contact') {
          $queryObjects[] = new CRM_Extname_BAO_Query();
      }
  }
  
  ```
  
  **[myext]/CRM/Extname/APIWrapper/GetQuick.php**
  clas
  
  ```
  s CRM_Extname_APIWrapper_GetQuick implements API_Wrapper {
  
    public function fromApiInput($apiRequest) {
  
          if (!empty($apiRequest['params']['field_name'])) return $apiRequest;
  
          $apiRequest['entity'] = 'Contact';
          $apiRequest['action'] = 'getlist';
          $apiRequest['function'] = 'emulate_civicrm_api3_contact_getList';
  
          $apiRequest['params']['sequential'] = '1';
          $apiRequest['params']['nick_name'] = $apiRequest['params']['id'] = $apiRequest['params']['name'];
  
          unset($apiRequest['params']['name']);
          unset($apiRequest['params']['option']);
          unset($apiRequest['params']['task']);
          unset($apiRequest['params']['field_name']);
          unset($apiRequest['params']['table_name']);
  
          return $apiRequest;
    }
  
    // this never seems called
    public function toApiOutput($apiRequest, $result) {
  
        return $result;
    }
  
  }
  
  ```
  
  **[myext]/CRM/Extname/BAO/Query.php**
  
  ```
  class CRM_Extname_BAO_Query extends CRM_Contact_BAO_Query_Interface {
  
      function &getFields() {
          return ['id'];
      }
  
      function from($name, $mode, $side) {
          return '';
      }
  
      function where(&$query) {
  
          $grouping = NULL;
          foreach (array_keys($query->_params) as $id) {
              if (empty($query->_params[$id][0])) {
                  continue;
              }
  
              $this->whereClauseSingle($query->_params[$id], $query);         
          }
  
      }
  
      function whereClauseSingle(&$values, &$query) {
          list($name, $op, $value, $grouping, $wildcard) = $values;
  
          $fields = $this->getFields();
          if (!empty($value) && !is_array($value)) {
            $quoteValue = "\"$value\"";
          }
  
          // Look in CRM_Contact_BAO_Query:2025 for how this is all gatherered into or's and ands
  
          switch ($name) {
            case 'sort_name': 
              // the default search is grouping=0; this is pretty hard coded into CRM_Contact_BAO_Query
              if ($grouping==0) {
                  foreach ($query->_where[$grouping] as $key => $val) {
                      if (strpos($query->_where[$grouping][$key],'sort_name')===false) continue;
                      // search id if numeric
                      if (is_numeric($value)) {
                          $query->_qill[$grouping][$key] .= ' Or '.($value ? ts('Contact ID is '.$quoteValue) : ts('Contact ID is not '.$quoteValue));
                          $query->_where[$grouping][$key] .= ' OR '.CRM_Contact_BAO_Query::buildClause("contact_a.id", "=", (int)$value, "Int");
                      }
                      break;
                  }
              }
              return;
          }
  
      }
  
      public function getPanesMapper(&$panes) {
  
          return $panes;
      }
  
  }
  
  ```
  
  > **Comments:**
  > **username_2**: username_1, i don't follow "getting the Contact ID in the search suggestion in the quick search" since civi already provides this. guess i am misunderstanding something in your answer that a tweak might help  
  > **username_1**: I didn't see contact id on the search preference. Is there another location to turn it on to display on the quick search suggestions?  
  > **username_2**: what version civi you on?  
  > **username_2**: You should be seeing what is in screenshot here https://docs.civicrm.org/user/en/4.6/the-user-interface/searching/  
  > **username_1**: 4.7.x   The code above would put the contact id in the quick search box suggestions here: http://imgur.com/a/tOWmz   The other part makes it search the contact id by default when adding the contact ID to that box.  
  > **username_2**: sorry username_1, I was mis-reading 'in' to mean, as a selector, not as an 'output'. crossed wires. so yours is effectively adding 'contact id' as an option to what is already offered at civicrm/admin/setting/search?reset=1  
  > **username_3**: Will this Extension add Search by Contact ID to the New Contribution input screen? https://drive.google.com/file/d/0B774H5vmdPHQNVdXZ3N3MkNyM2s/view?usp=sharing  
  > **username_1**: While I am not 100% sure Carl, I believe it would. I have been using it to modify the results that are returned via the API. That selector uses the API.  
  
  ---
  
  ### Answer by username_2 on 2017-02-26. Score: 0
  
  It helps if you mention the version you are on. In the Quick Search you should be able to see a setting when you click in there, to use Internal ID, then you can just enter the ID.
  
  Personally I would make it even simpler if you have been sent a spreadsheet, or can get their data in a spreadsheet, and use the CONCATENATE function in your spreadsheet so you have a link from there to go directly to a link this this civicrm/contact/view/contribution?reset=1&action=add&cid=XXX&context=contribution where XXX is the Internal ID
  
  
  ---
  
  ### Answer by username_3 on 2017-03-10. Score: 0
  
  You can add the contributions using Contact ID via the Import interface. Create a csv file with the contribution info and import it.
  
  But for the long term, I think this would be a brilliant addition to the New Contribution > Select Contact or Batch Entry > Select Contact search parameters. When people mail a check, our paper receipts have a tear off portion at that bottom that they can use with their next contribution. We could have it print their Contact ID in that lower section and use it when doing the data entry just as username_0 described and it should save on selecting the wrong donor with a similar name (or we have some with the same name).
  
  
  ---
  
  