Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 79901

Duplicate detection when add another record which has same 2 columns in the subgrid.

$
0
0

private static void duplciatedetection(Entity target, IOrganizationService service, ITracingService tracingService)
{
Entity targetEntity = (Entity)target["Target"];

if (targetEntity.LogicalName == "Subgrid_new_1")
{
OptionSetValue optionSetValue = target.GetAttributeValue<OptionSetValue>("A");
EntityReference lookupValue = target.GetAttributeValue<EntityReference>("B");

QueryExpression query = new QueryExpression("Subgrid_new_1");
query.Criteria.AddCondition("A", ConditionOperator.Equal, optionSetValue.Value);
query.Criteria.AddCondition("B", ConditionOperator.Equal, lookupValue.Id);
EntityCollection results = service.RetrieveMultiple(query);

if (results.Entities.Count > 0)
{
throw new InvalidPluginExecutionException("A record with the same Option Set value and Lookup value already exists in the subgrid.");
}

}
}


Viewing all articles
Browse latest Browse all 79901

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>