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:

 

3 Comments on “How to Retrieve Duplicates using WebApi

  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
    }
    );
    }

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.