Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

How to enable duplicate detection through C# code?

Posted on by 50

Hi,

I have set a duplicate detection rule for Contact entity - for fields firstname and last name , exact match.

  • This is working fine if I manually create a Contact record.

But i need to detect duplicates from C# code in which i am trying to create a Contact record using WebApi.

Can any one help me by suggesting me how to call this WebApi- MSCRM.SupressDuplicateDetection

private static async Task CreateRecord(HttpClient httpClient)

        {

            httpClient.DefaultRequestHeaders.Add("MSCRM.SupressDuplicateDetection", "false");

            var contact1 = new JObject

                        {

                            { "firstname", "" },

                            { "lastname", "" }

                        };

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "contacts")

            {

                Content = new StringContent(contact1.ToString(), Encoding.UTF8, "application/json")

            };

            HttpResponseMessage response = await httpClient.SendAsync(request);

            httpClient.DefaultRequestHeaders.Add("MSCRM.SupressDuplicateDetection", "false");

            if (response.StatusCode == HttpStatusCode.NoContent)

            {

               

                Console.WriteLine("Succeeded");

            }

            else

            {

                Console.WriteLine("Operation failed: {0}", response.ReasonPhrase);

            }

        }

Tried this but didn't work.

Thanks in advance.

  • Suggested answer
    Ramune Profile Picture
    Ramune on at
    RE: How to enable duplicate detection through C# code?

    Hi Priya,

    I did move this thread to CRM forum. I think your question is related CRM. If not, please let us know.

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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans