Skip to main content

Notifications

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

}
}

  • Suggested answer
    Tamilarasu Arunachalam Profile Picture
    558 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

  • 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.

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

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 671 Super User 2025 Season 1

#2
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 167 Super User 2025 Season 1

#3
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 138 Most Valuable Professional

Product updates

Dynamics 365 release plans