Answers.Body: <p>This isn't going to help now, but big-picture, there ought to be an aliasing system for names.  This Nickname problem occurs for organizations in an even bigger way, and Legal Name won't match with Organization Name.</p>
  
  <p>What ought to happen is that Nickname should be considered an alias of First Name, and you could have multiple aliases for it.  Someone could set up a maiden name as an alias of the last name, for example.  On the organization side, aliases for Organization Name could bypass all kinds of relationship chaos that happens when people set their Current Employer.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-14T15:26:58.313Z
Answers.LastActivityDate: 2015-04-14T15:26:58.313Z
Answers.UserDisplayName: Andie Hunt
Answers.Body: <p>You can create a view only custom field that you set with a civicrm_post hook when contacts are created/edited. It has the value of nickname if nickname isn't null, else first_name. Use that field in your dedupe rule.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-23T12:51:43.680Z
Answers.Text: Clever. It seems like this would fix my example case, which I like. But it also seems that it would break other cases (that currently work) where the contact would fill out a form using their formal first name, e.g. "Robert". So in the end, unless I'm missing something, it seems like this approach would be one step forward, and one step back :/
Answers.UserDisplayName: Sean
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-24T04:38:12.820Z
Answers.Text: @SeanMadsen - Good point.  The answer:  Match on first name, the custom field as 1 point.  Set last name as 2 , and set the dedupe threshold to 3.  That will satisfy both use cases, and avoid collision between "Robert Bob Smith" and "Robert Bob Jones".
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-14T01:49:47.393Z
Answers.LastActivityDate: 2015-04-14T01:49:47.393Z
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.Body: <p>You can use a list of nicknames, like <a href="https://github.com/carltonnorthern/nickname-and-diminutive-names-lookup" rel="nofollow noreferrer">this one</a> to find all contacts with a common name. Once you've found a list of &quot;Andrew&quot; first names, loop through each Andrew contact and find all of the &quot;Andy&quot; contacts plus &quot;Andrew's&quot; last name and email or phone number. From here, if you identify a duplicate, you can set the nickname for both contacts to the first name of the duplicate contact (&quot;Andy&quot;) then run a Dedupe rule like this: Nickname + (Phone or Email). Here's the script I used to do this:</p>
  <pre><code>function setContactNicknames() {
      $nicknames = explode(&quot;\n&quot;, file_get_contents(__DIR__ . '/nicknames.csv'));
  
      foreach($nicknames as $rootNames) {
          $rootNameFound = null;
          $eachRoot = explode(',', $rootNames);
  
          foreach($eachRoot as $nickname) {
              if ($rootNameFound) {
                  foreach($rootNameFound['values'] as $rootContact) {
                      $nickMatch = null;
  
                      if ($rootContact['email']) {
                          $nickMatch = civicrm_api3('Contact', 'get', [
                              'sequential' =&gt; 1,
                              'first_name' =&gt; &quot;{$nickname}&quot;,
                              'last_name' =&gt; $rootContact['last_name'],
                              'email' =&gt; $rootContact['email']
                          ]);
                      }
  
                      if (!$nickMatch &amp;&amp; $rootContact['phone']) {
                          $nickMatch = civicrm_api3('Contact', 'get', [
                              'sequential' =&gt; 1,
                              'first_name' =&gt; &quot;{$nickname}&quot;,
                              'last_name' =&gt; $rootContact['last_name'],
                              'phone' =&gt; $rootContact['phone']
                          ]);
                      }
  
                      if ($nickMatch &amp;&amp; $nickMatch['count']) {
                          $matchContact = $nickMatch['values'][0];
                          $setNickname = $matchContact['first_name'];
  
                          if ($rootContact['contact_id'] !== $matchContact['contact_id']) {
                              civicrm_api3('Contact', 'create', [ 'id' =&gt; $rootContact['contact_id'], 'nick_name' =&gt; $setNickname, ]);
                              civicrm_api3('Contact', 'create', [ 'id' =&gt; $matchContact['contact_id'], 'nick_name' =&gt; $setNickname, ]);
  
                              echo $rootContact['first_name'] . ' ' . $rootContact['contact_id'] . ' ';
                              echo $matchContact['first_name'] . ' ' . $matchContact['contact_id'] . ' ';                            
                          }
                      }
                  } 
  
              } else {
                  $searchName = civicrm_api3('Contact', 'get', [ 'sequential' =&gt; 1, 'first_name' =&gt; &quot;{$nickname}&quot;, ]);
  
                  if ($searchName['count']) {
                      $rootNameFound = $searchName;
                  }
              }
          }
      } 
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-17T18:11:33.233Z
Answers.LastActivityDate: 2022-02-17T18:11:33.233Z
Answers.UserDisplayName: dsmith63
Answers.Body: <p>I'm testing this dedupe rule out. It must match both partial first name (3 characters) and last name and either email or phone.</p>
  <p><a href="https://i.sstatic.net/dMmaI.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/dMmaI.png" alt="partialfirstdeduperule" /></a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-10-22T17:20:01.630Z
Answers.Text: This catches cases like "Rob" -> "Robert", "Dan" -> "Daniel".
Answers.UserDisplayName: dsmith63
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-10-22T17:59:01.633Z
Answers.Text: but not "Bob" > "Robert, "Tony" > "Anthony" or "Mandy" > "Amanda" unfortunately
Answers.UserDisplayName: petednz - fuzion
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-02-18T14:28:25.927Z
Answers.Text: @petednz-fuzion I added a new solution, in case you're interested.
  https://civicrm.stackexchange.com/a/41307/8784
Answers.UserDisplayName: dsmith63
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-10-22T17:06:59.283Z
Answers.LastActivityDate: 2021-10-22T17:06:59.283Z
Answers.UserDisplayName: dsmith63
Body: <p>Here's an example of a very common situation I have:</p>
  
  <ol>
  <li><p>Database has a contact like this</p>
  
  <ul>
  <li>first name: Robert</li>
  <li>nick name: Bob</li>
  <li>last name: Smith</li>
  <li>email: bobsmith@example.com</li>
  <li>...</li>
  </ul></li>
  <li><p>Event registration form receives a submission like this</p>
  
  <ul>
  <li>first name: Bob</li>
  <li>last name: Smith</li>
  <li>email: bobsmith@example.com</li>
  <li>...</li>
  </ul></li>
  <li><p>A duplicate contact is created because the first name values do not match. </p></li>
  </ol>
  
  <p>When finding duplicate contacts, is there some way of getting Civi to notice that the <em>first name</em> of one contact is identical to the <em>nick name</em> of another contact? </p>
  
  <p>As a workaround, I've tried adding the nick name field to public forms, but trust me you don't want to do this. It's funny seeing what people write when prompted for a nick name, but not so funny when you notice postal solicitations addressed to people like "The Dude Smith". </p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-04-13T18:59:46.277Z
Comments.Text: As an alternative workaround, perhaps the dedupe rule needn't consider first name?  Are you getting a lot of unsupervised dedupe interactions where 2 folks share an e-mail address and last name?
Comments.UserDisplayName: Jon G - Megaphone Tech
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-04-14T01:39:53.897Z
Comments.Text: Good thinking, Jon, But I definitely have a lot of cases were different people have same email and same last name.
Comments.UserDisplayName: Sean
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-04-14T11:48:22.470Z
Comments.Text: Yeah, the problem is that most people who share emails (or phones, for that matter) in general are family members, often with the same last name.
Comments.UserDisplayName: Andie Hunt
Tags: <duplicate-contacts>
Title: How do I find duplicate contacts by nickname?
ThreadText: # How do I find duplicate contacts by nickname?
  
  (Asked by: username_0 on 2015-04-13)
  
  Here's an example of a very common situation I have:
  
  1. Database has a contact like this
  
     * first name: Robert
     * nick name: Bob
     * last name: Smith
     * email: bobsmith@example.com
     * ...
  2. Event registration form receives a submission like this
  
     * first name: Bob
     * last name: Smith
     * email: bobsmith@example.com
     * ...
  3. A duplicate contact is created because the first name values do not match.
  
  When finding duplicate contacts, is there some way of getting Civi to notice that the *first name* of one contact is identical to the *nick name* of another contact?
  
  As a workaround, I've tried adding the nick name field to public forms, but trust me you don't want to do this. It's funny seeing what people write when prompted for a nick name, but not so funny when you notice postal solicitations addressed to people like "The Dude Smith".
  
  **Tags:** duplicate-contacts
  
  > **Comments:**
  > **username_1**: As an alternative workaround, perhaps the dedupe rule needn't consider first name?  Are you getting a lot of unsupervised dedupe interactions where 2 folks share an e-mail address and last name?  
  > **username_0**: Good thinking, Jon, But I definitely have a lot of cases were different people have same email and same last name.  
  > **username_2**: Yeah, the problem is that most people who share emails (or phones, for that matter) in general are family members, often with the same last name.  
  
  ---
  
  ## 4 answers
  
  ### Answer by username_2 on 2015-04-14. Score: 4
  
  This isn't going to help now, but big-picture, there ought to be an aliasing system for names. This Nickname problem occurs for organizations in an even bigger way, and Legal Name won't match with Organization Name.
  
  What ought to happen is that Nickname should be considered an alias of First Name, and you could have multiple aliases for it. Someone could set up a maiden name as an alias of the last name, for example. On the organization side, aliases for Organization Name could bypass all kinds of relationship chaos that happens when people set their Current Employer.
  
  
  ---
  
  ### Answer by username_1 on 2015-04-14. Score: 3
  
  You can create a view only custom field that you set with a civicrm\_post hook when contacts are created/edited. It has the value of nickname if nickname isn't null, else first\_name. Use that field in your dedupe rule.
  
  > **Comments:**
  > **username_0**: Clever. It seems like this would fix my example case, which I like. But it also seems that it would break other cases (that currently work) where the contact would fill out a form using their formal first name, e.g. "Robert". So in the end, unless I'm missing something, it seems like this approach would be one step forward, and one step back :/  
  > **username_1**: @SeanMadsen - Good point.  The answer:  Match on first name, the custom field as 1 point.  Set last name as 2 , and set the dedupe threshold to 3.  That will satisfy both use cases, and avoid collision between "Robert Bob Smith" and "Robert Bob Jones".  
  
  ---
  
  ### Answer by username_3 on 2022-02-17. Score: 1
  
  You can use a list of nicknames, like [this one](https://github.com/carltonnorthern/nickname-and-diminutive-names-lookup) to find all contacts with a common name. Once you've found a list of "Andrew" first names, loop through each Andrew contact and find all of the "Andy" contacts plus "Andrew's" last name and email or phone number. From here, if you identify a duplicate, you can set the nickname for both contacts to the first name of the duplicate contact ("Andy") then run a Dedupe rule like this: Nickname + (Phone or Email). Here's the script I used to do this:
  
  ```
  function setContactNicknames() {
      $nicknames = explode("\n", file_get_contents(__DIR__ . '/nicknames.csv'));
  
      foreach($nicknames as $rootNames) {
          $rootNameFound = null;
          $eachRoot = explode(',', $rootNames);
  
          foreach($eachRoot as $nickname) {
              if ($rootNameFound) {
                  foreach($rootNameFound['values'] as $rootContact) {
                      $nickMatch = null;
  
                      if ($rootContact['email']) {
                          $nickMatch = civicrm_api3('Contact', 'get', [
                              'sequential' => 1,
                              'first_name' => "{$nickname}",
                              'last_name' => $rootContact['last_name'],
                              'email' => $rootContact['email']
                          ]);
                      }
  
                      if (!$nickMatch && $rootContact['phone']) {
                          $nickMatch = civicrm_api3('Contact', 'get', [
                              'sequential' => 1,
                              'first_name' => "{$nickname}",
                              'last_name' => $rootContact['last_name'],
                              'phone' => $rootContact['phone']
                          ]);
                      }
  
                      if ($nickMatch && $nickMatch['count']) {
                          $matchContact = $nickMatch['values'][0];
                          $setNickname = $matchContact['first_name'];
  
                          if ($rootContact['contact_id'] !== $matchContact['contact_id']) {
                              civicrm_api3('Contact', 'create', [ 'id' => $rootContact['contact_id'], 'nick_name' => $setNickname, ]);
                              civicrm_api3('Contact', 'create', [ 'id' => $matchContact['contact_id'], 'nick_name' => $setNickname, ]);
  
                              echo $rootContact['first_name'] . ' ' . $rootContact['contact_id'] . ' ';
                              echo $matchContact['first_name'] . ' ' . $matchContact['contact_id'] . ' ';                            
                          }
                      }
                  } 
  
              } else {
                  $searchName = civicrm_api3('Contact', 'get', [ 'sequential' => 1, 'first_name' => "{$nickname}", ]);
  
                  if ($searchName['count']) {
                      $rootNameFound = $searchName;
                  }
              }
          }
      } 
  }
  
  ```
  
  
  ---
  
  ### Answer by username_3 on 2021-10-22. Score: 0
  
  I'm testing this dedupe rule out. It must match both partial first name (3 characters) and last name and either email or phone.
  
  [![partialfirstdeduperule](https://i.sstatic.net/dMmaI.png)](https://i.sstatic.net/dMmaI.png)
  
  > **Comments:**
  > **username_3**: This catches cases like "Rob" -> "Robert", "Dan" -> "Daniel".  
  > **username_4**: but not "Bob" > "Robert, "Tony" > "Anthony" or "Mandy" > "Amanda" unfortunately  
  > **username_3**: @username_4 I added a new solution, in case you're interested. https://civicrm.stackexchange.com/a/41307/8784  
  
  ---
  
  