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 :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Field to show if a Contact has a duplicate

(0) ShareShare
ReportReport
Posted on by 479

Hi,

I would like a add a field to a Contact form to indicate if the Contact has a duplicate (based on a duplicate email address) in the system.

I was thinking of using a Rollup field but I'm not sure if that would work as they are same entity.

Anyone have any suggestions?

Thanks a lot.

Ted

I have the same question (0)
  • Suggested answer
    manojd Profile Picture
    1,397 on at

    Hi,

    are you looking to have this field before while creating record or after you created the record?

    If you want while creating record you will have to write javascript code to check the contact data by passing the current email id & basis on the result you can flag the field showcasing whether its duplicate

    Thanks

  • Suggested answer
    T.I.A Profile Picture
    1,760 on at

    Hi,

    If you want to do a report on it then using the Deduplicator from the XrmToolBox will be able to reveal all of the duplicates: www.xrmtoolbox.com/.../

    Otherwise you have many other things that can detect duplicates (pre-operation plugins, JS).

    Finally duplicate detection rules can run on criteria that you desire: docs.microsoft.com/.../set-up-duplicate-detection-rules-keep-data-clean

  • Suggested answer
    Kokulan Profile Picture
    18,054 on at

    Hi

    As suggested by T.I.A, better to stick to CRM Out of the box duplicate detection functionalities. However, if you definitely want a flag field on Contact to see if there is duplicate or not, you could try the following

    01. Create  Flow that triggers on Contact Create / Update and queries and checks if there are more than one contacts with the same email, you can update the record flag field value.

    02. You can write a plugin that triggers on Pre/post update and checks and sets the flag

    03. You  could create a custom workflow activity to check and set the flag and call the CWA in a workflow that triggers on Create of the record or update of email field.

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hello ,

    I am not sure  is there any reason behind to having flag field ? If you don't allow duplicates , create OOTB duplicate detection rules to warn duplicates records which is the best way to handle.

    Rollup field basically aggregate value computed over the records related to specific record. So you need to have the relationship with 1:N. So in same entity for your scenario its not possible .

    Secondly if you are allowing duplicates , you need to set flag field at the time you are creating the record , which means you also need to take care the flag field later when you delete or  update  any record email  . So JavaScript wont  be a good idea in that case because you might do those operation from anywhere. I would suggest to create plugin and register in create/ update/delete event and calculate the the flag based on duplicates record . If you are familiar with  flow you will get no code approach as well so go for that instead of plugins.

  • necsa Profile Picture
    3,455 on at

    Hi,

    Get as reference following Plugin and assign the value as you wish to field on the contact.

    using System;
    using Microsoft.Xrm.Sdk;
    using Microsoft.Xrm.Sdk.Query;

    namespace DuplikateCheck
    {
        public class CheckDuplikate:IPlugin
        {
            public void Execute(IServiceProvider serviceProvider)
            {
                IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

                //Get a reference to the Organization service.

                IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                IOrganizationService service = factory.CreateOrganizationService(context.UserId);

                if(context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
                {
                    //Obtain the target entity from the input parameter

                    Entity contact = (Entity)context.InputParameters["Target"];

                    try
                    {
                        //Implement Plugin Business Logic here

                        string email = string.Empty; //Variable declared to check whether emailaddress field is empty or not.

                        if (contact.Attributes.Contains("emailaddress1"))
                        {
                            email = contact.Attributes["emailaddress1"].ToString();

                            QueryExpression query = new QueryExpression("contact");
                            query.ColumnSet = new ColumnSet(new string[] { "emailaddress1" });
                            query.Criteria.AddCondition("emailaddress1", ConditionOperator.Equal, email);

                            EntityCollection collection = service.RetrieveMultiple(query);

                            if(collection.Entities.Count > 0)  //Check if any record is present with duplicate email address
                            {
                               
                                // assign the value of field here
                                
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new InvalidPluginExecutionException(ex.Message);
                    }
                }
            }
        }
    }

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!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 182 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 123

#3
CU11031447-0 Profile Picture

CU11031447-0 100

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans