6

Here's an example of a very common situation I have:

  1. Database has a contact like this

  2. Event registration form receives a submission like this

  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".

3
  • 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? Commented Apr 13, 2015 at 18:59
  • Good thinking, Jon, But I definitely have a lot of cases were different people have same email and same last name.
    – Sean
    Commented Apr 14, 2015 at 1:39
  • 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.
    – Andie Hunt
    Commented Apr 14, 2015 at 11:48

4 Answers 4

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.

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.

2
  • 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 :/
    – Sean
    Commented Apr 23, 2015 at 12:51
  • 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". Commented Apr 24, 2015 at 4:38
1

You can use a list of nicknames, like this one 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;
                }
            }
        }
    } 
}
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

3
  • This catches cases like "Rob" -> "Robert", "Dan" -> "Daniel".
    – dsmith63
    Commented Oct 22, 2021 at 17:20
  • but not "Bob" > "Robert, "Tony" > "Anthony" or "Mandy" > "Amanda" unfortunately
    – petednz - fuzion
    Commented Oct 22, 2021 at 17:59
  • 1
    @petednz-fuzion I added a new solution, in case you're interested. civicrm.stackexchange.com/a/41307/8784
    – dsmith63
    Commented Feb 18, 2022 at 14:28

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.