Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

Why does my (RetrieveDuplicatesResponse)localContext.OrganizationService.Execute(request) always return zero count?

(0) ShareShare
ReportReport
Posted on by 137

Hi,

My CRM plugin needs to find if there is any duplicate records, so I use the following codes, basically I use two fields ("dev_claimnumber" and "dev_adminstratorstatus") as key to find if there is any duplicated records.

I know there is duplicates record already, but these codes does not work, the response.DuplicateCollection.Entities.Count always return 0, which it should be equaled to 1.

Any anybody help me to find what is wrong with my codes? or should I use other object or class to find the duplicated records? thanks a lot,

Peter

-----------------------------------------------------------

string EntityLogicalName = "dev_accountinfo";
Entity statusEntity = new Entity(EntityLogicalName);  
            statusEntity["dev_claimnumber"] = entity.Attributes["dev_claimnumber"].ToString(); //single line text field
            statusEntity["dav_adminstratorstatus"] = ((OptionSetValue)entity["dapi_administratorstatus"]).Value; //this is option set field           
            var request = new RetrieveDuplicatesRequest
            {
                BusinessEntity = statusEntity,
                MatchingEntityName = statusEntity.LogicalName,
                PagingInfo = new PagingInfo() { PageNumber = 1, Count = 50 }
            };          
            var response = (RetrieveDuplicatesResponse)localContext.OrganizationService.Execute(request);
            if (response.DuplicateCollection.Entities.Count == 0) //if there is no duplicate record found, create a record
            {
               localContext.Trace("No duplicates found... Entities.Count:" + response.DuplicateCollection.Entities.Count.ToString());
  //the above code shows Entities.Count:0, even I can see there are duplicate records it should returns 1

********************************************I also tried different codes as follows, but it also return zero of count****************

string EntityLogicalName = "dev_accountinfo";
            Entity statusEntity = new Entity(EntityLogicalName);
            QueryExpression Account = new QueryExpression { EntityName = "dev_accountinfo", ColumnSet = new ColumnSet("dev_claimnumber") };
            Account.Criteria.AddCondition("dev_claimnumber", ConditionOperator.Equal, entity.Attributes["dev_claimnumber"]);
            Account.Criteria.AddCondition("dev_administratorstatus", ConditionOperator.Equal, ((OptionSetValue)entity.Attributes["dapi_administratorstatus"]).Value);

            EntityCollection RetrieveAccount = localContext.OrganizationService.RetrieveMultiple(Account);
            if (RetrieveAccount.Entities.Count > 1)
            {
                localContext.Trace("duplicate records found..." + RetrieveAccount.Entities.Count.ToString());
            } else
            {
                localContext.Trace("no duplicates...");
            }

  • Charan Raju C R Profile Picture
    7 Moderator on at
    RE: Why does my (RetrieveDuplicatesResponse)localContext.OrganizationService.Execute(request) always return zero count?

    Glad that you're managed to identify the issue and fixed it. Have a good day!

  • Peter Cong Profile Picture
    137 on at
    RE: Why does my (RetrieveDuplicatesResponse)localContext.OrganizationService.Execute(request) always return zero count?

    Hi Charan, thanks for your help again,

    The problem was caused by the OptionSet value was not set properly, it should be set as int, but it was set as string.

  • Suggested answer
    Charan Raju C R Profile Picture
    7 Moderator on at
    RE: Why does my (RetrieveDuplicatesResponse)localContext.OrganizationService.Execute(request) always return zero count?

    Hi Peter,

    Does it work when you create a third duplicate record?

    Your plug-in is registered on pre-operation or post-operation?

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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 225 Super User 2025 Season 1

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 106 Most Valuable Professional

#3
Eugen Podkorytov Profile Picture

Eugen Podkorytov 102

Overall leaderboard

Product updates

Dynamics 365 release plans