Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

How to avoid duplicates when creating records using Web API (C#) ?

Posted on by

When I try to create a duplicate in the CRM web application I am getting a pop-up indicating that I am trying to create a duplicate record. However, if the create using Web API (C#) from a .Net application then by default, the duplicate record is getting created without any warning.

Here is the sample code we are using to using to create a record using Web API

 JObject accountRecord = new JObject();
            accountRecord.Add("name", "JKC");
            accountRecord.Add("accountnumber", "00112233");

            HttpRequestMessage createAccountReq =
               new HttpRequestMessage(HttpMethod.Post, getVersionedWebAPIPath() + "accounts");

            createAccountReq.Content = new StringContent(accountRecord.ToString(),
                Encoding.UTF8, "application/json");

            HttpResponseMessage createAccountRes =
                await httpClient.SendAsync(createAccountReq);


*This post is locked for comments

  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: How to avoid duplicates when creating records using Web API (C#) ?

    Hello,

    To turn on duplicates validation using webapi you should add new header "MSCRM.SuppressDuplicateDetection" to request with value "false".

    That should resolve your ussue.

  • Suggested answer
    Guido Preite Profile Picture
    Guido Preite 54,081 Super User 2024 Season 1 on at
    RE: How to avoid duplicates when creating records using Web API (C#) ?

    if you want to avoid duplicates create an alternate key connected to your unique attribute

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans