web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

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

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

(0) ShareShare
ReportReport
Posted on by 20

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

}
}

I have the same question (0)
  • Manth Profile Picture
    20 on at
    RE: Duplicate detection when add another record which has same 2 columns in the subgrid.

    Subgrid_new_1 is not a logical name even if i use the subgrid logical name i am facing same issue as above code.

    Fast reply is most helpful.

  • Suggested answer
    Tamilarasu Arunachalam Profile Picture
    587 on at
    RE: Duplicate detection when add another record which has same 2 columns in the subgrid.

    Hi Manth ,

    I have done a similar thing before

    You should get the column values using columnset.

    just try the below snippet 

    queryExpression.ColumnSet = new ColumnSet("fullname", "emailaddress1", "parentcustomerid");
    
    queryExpression.Criteria.AddCondition("fullname".ToLower(), ConditionOperator.Equal, fullName.ToLower());
    queryExpression.Criteria.AddCondition("emailaddress1", ConditionOperator.Equal, email);
    queryExpression.Criteria.AddCondition("parentcustomerid", ConditionOperator.Equal, parentCustomerId.Id);

    if this answer helps you, like and verify my answer

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 117 Super User 2025 Season 2

#2
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 115

#3
Erin Lubben Profile Picture

Erin Lubben 66

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans