Duplicate contacts are getting created

Ashutosh Pandey asked on January 28, 2021 19:10

We are working on Kentico 10.

We import contacts provided to us as CSV (saving in OM_Contact table).

Then our system sends emails to these users, they come to our website and register themselves.

The problem is that we are seeing duplicate contacts (not users) getting generated.

It looks like the first contact is created when we imported and second when user is registered (which also creates contact).

How can we make sure user registration associates the user to existing contact and not creating a new contact.

The code to create user is something like this:

UserInfo user = new UserInfo();

user.set ... ....

UserInfoProvider.SetUserInfo(user); UserInfoProvider.AddUserToSite(user.Email, SiteContext.CurrentSiteName);

Thanks

Correct Answer

Brenden Kehren answered on January 29, 2021 15:20

Yes, when you use the import contacts feature of Kentico, it will import them into the OM_Contact table.

To create a new contact, you use the ContactInfo and ContactInfoProvider classes, not the UserInfo class. Users and Contacts are two different things, however, they can be related. Below are some links to the API Examples:

https://docs.xperience.io/api10/on-line-marketing/contacts

If you want make sure you don't create a contact twice, then you will have to check that manually based on your rules. For instance:

var contact = ContactInfoProvider.GetContacts().WhereEquals("ContactEmail", inputEmail).And().WhereEquals("ContactFirstName", inputFirstName).And().WhereEquals("ContactLastName", inputLastName);   

if (contact == null)
{ 
    // create a new contact
}
else
{
    // contact exists
}
0 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on January 28, 2021 20:54

I'd highly recommend importing those contacts through the Kentico UI vs. writing code or importing directly into the database table. In v10 there isn't much for duplicate checking but you can use the Merge tool to merge 2 contacts together.

Also, you need to be sure what you're talking about. You reference the OM_Contact table. This is a contact. Then you showed code pointing at the UserInfoProvider. This is a user account, someone who would log into a site. A user can be tied to a contact via the ContactUserID field in the OM_Contact table. So maybe having a better understanding of exactly what you're talking about would be the first step.

0 votesVote for this answer Mark as a Correct answer

Ashutosh Pandey answered on January 29, 2021 09:53

Thanks Branden, I think I was not able to explain the problem properly.

My question is, if we import a contact from Kentico UI => admin (email and name), will it go to OM_Contact table?

And after that, if we register a new user with the code above, will it create a new contact?

If it creates a new contact, then how in code can we avoid this?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.