Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Field to show if a Contact has a duplicate

Posted on by 460

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

  • necsa Profile Picture
    necsa 3,455 on at
    RE: Field to show if a Contact has a duplicate

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

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Field to show if a Contact has a duplicate

    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.

  • Suggested answer
    Kokulan Profile Picture
    Kokulan 18,048 on at
    RE: Field to show if a Contact has a duplicate

    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
    T.I.A Profile Picture
    T.I.A 1,760 on at
    RE: Field to show if a Contact has a duplicate

    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
    manojd  Profile Picture
    manojd 1,397 on at
    RE: Field to show if a Contact has a duplicate

    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

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

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans