Skip to main content

Notifications

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

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

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
    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
    Manth 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans