Blog, Development

How to Retrieve Duplicates using WebApi

In this post I provide 2 ways to retrieve duplicates – using plain JS way and with usage of Xrm.WebApi namespace that was introduced as a part of 9.0 release.

So here is plain JS:

And here is Xrm.WebApi version:

 

6 Comments

  1. Hi Andrew,

    I have used same webApi method (just Copy-Pasted) to retrieve duplicates in online trial environment. I’m getting error like “Resource not found for the segment ‘Retrieve Duplicates'”. Do you have any Idea ?

    1. Hello,
      I checked and it works fine for me. What exactly did you do with code and where you tried it?
      Thanks,
      Andrew

  2. Hi…I have not modified anything, just used your code as it is in my custom Js file. my online trial version 9.1

    Here is the method I’m calling on form load and getting error “Resource not found for the segment ‘Retrieve Duplicates’”

    this.retrieveDuplicatesWebApi = function () {
    var contactRecord = {
    “@odata.type”: “Microsoft.Dynamics.CRM.contact”,
    “firstname”: “Andrew”,
    “lastname”: “Butenko”
    };

    var pagingInfo = {
    “PageNumber”: 1,
    “Count”: 10
    };

    var retrieveDuplicatesRequest = {
    BusinessEntity: contactRecord,
    MatchingEntityName: “contact”,
    PagingInfo: pagingInfo,
    getMetadata: function () {
    return {
    boundParameter: null,
    parameterTypes: {
    “BusinessEntity”: {
    “typeName”: “mscrm.crmbaseentity”,
    “structuralProperty”: 5
    },
    “MatchingEntityName”: {
    “typeName”: “Edm.String”,
    “structuralProperty”: 1
    },
    “PagingInfo”: {
    “typeName”: “mscrm.PagingInfo”,
    “structuralProperty”: 5
    }
    },
    operationType: 1,
    operationName: “RetrieveDuplicates”
    };
    }
    };

    Xrm.WebApi.online.execute(retrieveDuplicatesRequest).then(
    function success(result) {
    if (result.ok) {
    var results = JSON.parse(result.responseText);
    //you’ve got results to results variable
    }
    },
    function (error) {
    var errorText = error.message;
    //handle error here
    }
    );
    }

  3. Hello, i have the same issue as Praveen. “Resource not found for the segment ‘Retrieve Duplicates”
    So strange, i tried almost everything and didn’t managed to solve the problem. Andrew is there any chance you expirienced and solved this issue somehow?

    Спасибо,
    Юрий

    1. Юрий,
      I tried the “Xrm.WebApi way” and it doesn’t work anymore for some reason but the old-fashioned way with the use of XmlHttpRequest still works.
      Андрій

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.