web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Duplicate Detection rule, prevent the record from saving

(0) ShareShare
ReportReport
Posted on by 1,023

Hello Team,

I have implemented the duplicate detection rule in one of my custom entity.

Now the Duplicate Detection rule is working and it is showing the Duplicate message.

But, In Duplicate detection message it is having the option to save. I don't want to save the record if duplicate detection is detected.

Any help or guidance will be highly appreciated.

Thanks

*This post is locked for comments

I have the same question (1)
  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    Unfortunately there is no possibility to make it in customization way.

    I believe that's possible with plugin that will handle Create, run duplicate detection and if this record is duplicate just throw an error that will break creation of record.

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi James,

    This can be done by setting attributes on Keys within the entity.

    For example, if you wanted to prevent duplicate Contacts that match on Name and Company:

    1) Open Contacts entity

    2) Select Keys on the Contact entity

    3) Click NEW and give the Display Name a descriptive label (i.e. "Duplicate Contact on Name & Company Match")

    4) Tab over and accept the value that auto populates the Name field

    5) In the Available Attributes Section, select and add "First Name," "Last Name," and "Company Name"

    6) Save and Publish your customizations

    Result: when a user tries to save a duplicate Contact that matches on those fields, an error pops stating "ERROR: Duplicate Record. A duplicate with attribute values First Name, Last Name, Company Name already exists.  The entity key requires unique values - try again. Download log file / OK." Those are the only two options the user receives - no option to save as when using duplicate detection rules.

  • Community Member Profile Picture
    on at

    Please see my reply to OP. This is possible using entity keys.

  • Community Member Profile Picture
    on at

    This can be done by setting attributes on Keys within the entity.

    For example, if you wanted to prevent duplicate Contacts that match on Name and Company:

    1) Open Contacts entity

    2) Select Keys on the Contact entity

    3) Click NEW and give the Display Name a descriptive label (i.e. "Duplicate Contact on Name & Company Match")

    4) Tab over and accept the value that auto populates the Name field

    5) In the Available Attributes Section, select and add "First Name," "Last Name," and "Company Name"

    6) Save and Publish your customizations

    Result: when a user tries to save a duplicate Contact that matches on those fields, an error pops stating "ERROR: Duplicate Record. A duplicate with attribute values First Name, Last Name, Company Name already exists.  The entity key requires unique values - try again. Download log file / OK." Those are the only two options the user receives - no option to save as when using duplicate detection rules.

  • Community Member Profile Picture
    on at

    Hi msQQ94SID,

    I tried to create a new key on Lead, but it Failed. Is there any way you can tell why it failed? I do have the duplicate detection enabled. Should the attributes in key and the duplicate detection rule be same or it can be different? Any suggestions would be much appreciated.

    failed.jpg

    Thanks,

    Sam

  • Community Member Profile Picture
    on at

    Hi,

    I also tried the same. First time it failed. I delete the key and tried once again. Now it works. 

    Thanks.

  • Community Member Profile Picture
    on at

    It did not work for me. Thanks Gokul.

  • Suggested answer
    Dynamics_Alok Profile Picture
    1,746 on at

    key decides duplication based on key(attribute) value only but duplicate detection decides duplication based on DDR.

    To resolve your issue ,better way is to write Javascript or Plugin to stop saving duplicate record.

  • Taryn Profile Picture
    25 on at

    Thank for this, works perfectly

  • Suggested answer
    Iswarya Profile Picture
    1,347 on at

    hi,

    you can achieve the same, using javascript. call this script in form onsave and enable ->pass Excution context as first parameter

    function GetData(executionObj)
    {
        debugger;
        var PracticeLocation = Xrm.Page.getAttribute("new_practicelocation").getValue();
        var EMRvendorProduct=Xrm.Page.getAttribute("new_emrvendorexist").getValue();

        if (PracticeLocation != null && EMRvendorProduct!=null )
        {

            var PracticeLocationId = PracticeLocation[0].id;

            var PracticeLocationName = PracticeLocation[0].name;

            var EMRvendorProductId = EMRvendorProduct[0].id;

            var EMRvendorProductName = EMRvendorProduct[0].name;

            var context = Xrm.Page.context;
            var serverUrl = context.getClientUrl();
            var ODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";
            var retrieveResult = new XMLHttpRequest();
           
            retrieveResult.open("GET", ODataPath +"/new_emrrequestSet?$select=new_emrvendorexist,new_PracticeLocation&$filter=new_emrvendorexist/Id eq  guid'"+EMRvendorProductId+"' and new_PracticeLocation/Id eq guid'"+PracticeLocationId+"'",false);
            retrieveResult.setRequestHeader("Accept", "application/json");
            retrieveResult.setRequestHeader("Content-Type", "application/json; charset=utf-8?");
            retrieveResult.send();

            if (retrieveResult.readyState == 4 /* complete */)
            {
                if (retrieveResult.status == 200)
                {
                    var retrieved = this.parent.JSON.parse(retrieveResult.responseText).d;
                    var Result = retrieved.results;
                   
                    if (typeof Result !== "undefined")
                    {
                        
                        var count = Result.length;

                        if (count>1)
                        {
                            alert("duplicate value not allowed");
                            executionObj.getEventArgs().preventDefault();

                        }

                    }
                }

            }

        }
    }



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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans