Announcements
No record found.
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
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
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
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.
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.
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.
Congratulations to our 2026 Super Stars!
Thanks to all of our 2025 Community Spotlight stars!
These are the community rock stars!
Stay up to date on forum activity by subscribing.
ManoVerse 182 Super User 2026 Season 1
11manish 123
CU11031447-0 100