Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Suppress Duplicate Detection with javascript

Posted on by 215

Hi guys, 

I'm trying to find a way to suppress the duplicate detection using javascript, is this possible at all?

The reason for this is because i'm creating an account using javascript and sometimes when the user clicks save on the duplicate detection rule the account does not get created because the detection rule fires before the account is created and it stops the function. Sample code is bellow, any suggestions or ideas are welcomed.

Code sample:

//create new account entity
                var createAccount = new XrmServiceToolkit.Soap.BusinessEntity("account");
                //validate name
                if (Xrm.Page.getAttribute("firstname").getValue() == null) {
                    alert("Name of potential supplier is missing, please provide it before continuing");
                    return;
                }
                else {
                    createAccount.attributes["name"] = Xrm.Page.getAttribute("firstname").getValue();
                }
                //validate primary contact
                if (Xrm.Page.getAttribute("parentcontactid").getValue() == null) {
                    alert("Please select a primary contact first");
                    return;
                }
                else {
                    createAccount.attributes["primarycontactid"] = { id: Xrm.Page.getAttribute("parentcontactid").getValue()[0].id, logicalName: "contact", type: "EntityReference" };
                }
                createAccount.attributes["address1_country"] = Xrm.Page.getAttribute("address1_composite").getValue();
                createAccount.attributes["websiteurl"] = Xrm.Page.getAttribute("websiteurl").getValue();
                createAccount.attributes["originatingleadid"] = { id: Xrm.Page.data.entity.getId(), logicalName: "lead", type: "EntityReference" };
                // check if lead has already been qualified
                if (Xrm.Page.getAttribute("statuscode").getValue() == 3 && Xrm.Page.getAttribute("statecode").getValue() == 1) {
                    alert("This lead has already been qualified");
                    return;
                }
                // qualify lead
                Xrm.Page.getAttribute("statuscode").setValue(3);
                Xrm.Page.getAttribute("statecode").setValue(1);
                Xrm.Page.data.save().then(function OnSuccess() {
                    var accountId = XrmServiceToolkit.Soap.Create(createAccount);
                    //Open newly created account record
                    Xrm.Utility.openEntityForm("account", accountId);
                }, function ErrorCallback(e) {
                    alert(e.message);
                    console.log("error");
                })


*This post is locked for comments

  • Suggested answer
    Arun Vinoth Profile Picture
    Arun Vinoth 11,613 on at
    RE: Suppress Duplicate Detection with javascript

    Filip,

    Instead of dummy attribute & invoking a plugin on that change, you can write a custom action & execute that from button click directly.

  • Filip Vanchevski Profile Picture
    Filip Vanchevski 215 on at
    RE: Suppress Duplicate Detection with javascript

    I found a workaround, but it required writing a plugin, so i don't create the new record with JavaScript, i put another hidden field on the form and changed the value on a click of a ribbon button, this was my trigger to activate the plugin and create the new record.

    Now from the plugin i was able to send create requests where I disabled the dupplicate detection rule.

    It took some work but i got it done.

  • Verified answer
    Arun Vinoth Profile Picture
    Arun Vinoth 11,613 on at
    RE: Suppress Duplicate Detection with javascript

    Fact is Duplicate detection rule will trigger & ask confirmation from user, if user confirms it will still create the dupe record. You have to decide to keep or remove the duplicate detection rule.

    Then .save().then() may not work for you in this scenario. Did you check if the record is created but the newly created record form is not just opened?

    Like I explained in Stack Overflow, SupressDuplicateDetection will work with Execute issuing CreateRequest only. Not with odata or soap in JavaScript.

    [View:https://stackoverflow.com/a/45645970/7920473]

  • KylieKiser Profile Picture
    KylieKiser 2,174 on at
    RE: Suppress Duplicate Detection with javascript

    Are you using Duplicate Detection on another entity? Or can you turn it off so it does not fire on create?

    You can still run duplicate detection jobs even if it is not automatically firing.

  • David Jennaway Profile Picture
    David Jennaway 14,063 on at
    RE: Suppress Duplicate Detection with javascript

    Can you clarify if you want to suppress the duplication detection of the record displayed in the form, or the record created by javascript ?

    If it's the record created by javascript, then I don't think you can pass the SuppressDuplicateDetection parameter, but I did create a workaround using a plugin that you could selectively trigger from javascript - see https://mscrmuk.blogspot.co.uk/2014/04/controlling-duplicate-detection.html 

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,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans