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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested Answer

Check multiselect optionset value using query expression

(0) ShareShare
ReportReport
Posted on by 1,000

Hi Techies,

I have one entity with multiselect optionset field and I want to check whether the options are already saved or not while saving new record.If already present then we need to throw the duplicate record warning.

for ex: I already saved one record with a,b,c options in multiselectoptionset. Now I try to save another record with a,b,d , the system should allow me to save the record. Because both options are not exact match.

If I use the below code its not working.If we use In condition it will not suitable for the below scenario.

Lets say If I try to save a,b options in multiselectoptionset It will check with existing record (a,b,c option record). The new value a,b already present in the existing record so it will return the record. But I need to check the exact options should match.

If I try to save a,b,c once again I want to throw the duplicate match  error. But If I try a,b,d or a,b or a or b the system should allow to be consider as a non duplicate.

How can I retrieve the exact match options through queryexpression ? TIA.

Entity entity = (Entity)context.InputParameters["Target"];
if (entity.Attributes.Contains("abc_multiselectfieldname"))
{
	OptionSetValueCollection collection = (OptionSetValueCollection)entity.Attributes["abc_multiselectfieldname"];                           
	QueryExp.Criteria.AddCondition("abc_multiselectfieldname", ConditionOperator.IN, collection);
}


I have the same question (0)
  • Amit Yadav4 Profile Picture
    70 on at

    Hi,

    Did you able to resolve this?

  • vijay12872 Profile Picture
    1,000 on at

    Amit Yadav4 Still No..

  • Community Member Profile Picture
    on at

    Hi user12872,

    Perhaps you could start by getting the number of items selected for each multi-select option set field,then compare them separately.

  • Ray Profile Picture
    1,537 on at

    You should use ConditionOperator.Equal rather then ConditionOperator.In.

  • vijay12872 Profile Picture
    1,000 on at

     R@y If I changed the condition operator to Equal I'm getting the following error,

    Element 'schemas.microsoft.com/.../Arrays:anyType' contains data from a type that maps to the name

    'Microsoft.Xrm.Sdk:OptionSetValueCollection'. The deserializer has no knowledge of any type that maps to this name.

    Consider changing the implementation of the ResolveName method on your

    DataContractResolver to return a non-null value for name 'OptionSetValueCollection' and namespace 'Microsoft.Xrm.Sdk'.

  • Suggested answer
    Bipin D365 Profile Picture
    28,985 Moderator on at

    Hi,

    Can you please apply filter in advance find then download the fetchXml.

    Now use fetchXml builder tool in xrmtoolbox to convert to query expression to see the syntax.

    I think you need to use contains value operator and pass string value

  • Ray Profile Picture
    1,537 on at

    I tried both QueryExpression and FetchXml but no lucky. I test in advance find when I select condition operator to "equal" for multiple option field, the fetchXml result will use to operator "in" to do the query. So I think you can use "in" to query first and then do an extra filter for result.

  • Suggested answer
    vijay12872 Profile Picture
    1,000 on at

    I'm using the following code logic to get the result,

    Entity entity = (Entity)context.InputParameters["Target"];

    if (entity.Attributes.Contains("abc_multiselectfieldname"))

    {

    OptionSetValueCollection collection = (OptionSetValueCollection)entity.Attributes["abc_multiselectfieldname"];

    int[] arrVal = new int[] {};

    foreach (var options in contigentLifeCollection)

    {

    arrVal = arrVal.Concat(new int[] { options.Value }).ToArray();

    }

    QueryExp.Criteria.AddCondition(new ConditionExpression("abc_multiselectfieldname", ConditionOperator.In, arrVal));

    }

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
11manish Profile Picture

11manish 174

#2
ManoVerse Profile Picture

ManoVerse 58 Super User 2026 Season 1

#3
Niki Patel Profile Picture

Niki Patel 42

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans