Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Duplicate records detection from Plugin

Posted on by 594

Hi CRM Folks,

What are my possibilities of preventing a duplicate case from getting created ?

1. Write a synchronous plugin and before creating a new case query all the CRM cases to check if any of the existing case title matches. If match is found throw error or else create new record.

Potential threat: It obviously creates a lot of performance problems as it is synchronous plugin and moreover for every case creation, it needs to query the whole CRM database to check if a matching record is found or not.

2. Create duplicate detection rule

Potential threat: This runs only if record is created from UI or from outlook. But this rule doesnt execute if you create a case record from workflow or using IOrganizationService.

What are my other possibilities of restricting creation of duplicate cases from synchronous plugin? (Something like using BulkDetectDuplicate request class or RetrieveDuplicatesRequest class. Appreciate if you can provide me some code related to these classes)?

Thanks in advance

*This post is locked for comments

  • Abdelrhman Hiba Profile Picture
    Abdelrhman Hiba 321 on at
    RE: Duplicate records detection from Plugin

    Hi All  ihave the same problem but i want to apply SuppressDuplicateDetection  in my costume business logic

    between Agreement, AgreementBookingSetup, AgreementBookingDates Entities 

    for each Agreement have a multiple AgreementBookingSetup and AgreementBookingSetup have a multiple AgreementBookingDates 

    to explaince the problem : 

    BookingDatesDublicates.jpg

    i want to delete repeating dates for (20/4/2019) for booking setup (M-Q-SA) Except A-Test

    because it have value option set (4)

    M=1

    Q=2

    SA=3

    so what is the pest way to apply SuppressDuplicateDetection   

    thanks 

  • Suggested answer
    Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Duplicate records detection from Plugin

    Hi,

    CRM server will store date in UTC format and based on users timezone it will display date to user accordingly. You can refer this post fore more details:www.magnetismsolutions.com/.../Set_Date_Time_Field_to_Now_in_Plugin_Dynamics_CRM_2011.aspx

  • chakkay Profile Picture
    chakkay 594 on at
    RE: Duplicate records detection from Plugin

    Great!Its working. Thanks a lot Alex & Mahender.

    One final question before closing this thread.

    One of the condition in duplicate detection rules is to compare created on date (not datetime) is same.....as we have 2 option to select 1. same date 2. Same Datetime

    I selected same date. Now in my plugin code what should i set this field to (as per your inogic post):

    _case.Attributes["createdon"] = ???????

    Is it DateTime.Now    or     DateTime.UtcNow    ???

    Or in other words: If i happen to create a case in plugin and set one of the custom attribute as _case.Attributes["custom datetime field"] = DateTime.Now() (and suppose i am in EST 05/10/2018 10:PM). What date will be stoared in CRM Server? Is it 05/10 10:00 PM or 05/11 2:00 AM UTC?

  • Verified answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: Duplicate records detection from Plugin

    Hi Chakkay,

     if you combine Mahender's suggestion with a pre-create plugin, you could try passing plugin target to RetrieveDuplicatesRequest

    www.inogic.com/.../use-retrieveduplicaterequest-in-dynamics-crm

     Then throw an error if there are duplicates..

     Not sure how those failures are going to affect the rest of your worklfows etc (another option might be to delete those duplicate cases in an asynchronous post-create plugin to avoid errors)

  • Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Duplicate records detection from Plugin

    Yes, for Automatic case creation you need to put your custom logic to look for duplicate record. You can write plugin on case pre create.

  • chakkay Profile Picture
    chakkay 594 on at
    RE: Duplicate records detection from Plugin

    Hey Mahender,

    Thanks a lot for quick reply.

    The above code applies only if you try to create a new record using plugin. But my scenario is "Automatic case create & update rule" is running in the backend and it creates a case. Now i want to restrict that case creation if there already exists a case with same case title. So i will be writing a synchronous plugin on case creation.

    If i use your above suggested code and execute method, am i not creating a case multiple times?

    Please correct me if i am wrong.

  • Verified answer
    Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Duplicate records detection from Plugin

    Hello,

    You can use duplicate detection in plugin as well, while creating record the only condition is you need to use Execute method instead of direct methods like create or update.

    You can look for sample here:

    msdn.microsoft.com/.../hh210213.aspx

    Hope it will help.

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans