Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to Add an optionset filter criteria in MS CRM Query Expression?

(1) ShareShare
ReportReport
Posted on by

I have an entity LeaveType with two attributes, 1. Type, 2. Available Days, where Type is an optionset and Available days is a text field. I want to fetch all such LeaveType records where the Type = 'Annual' selected in the optionset. I am not able to find how to add a filter the query expression for the option set value. Below is my in progress method:

public Entity Getleavetype(Guid LeaveDetailsId, IOrganizationService _orgService, CodeActivityContext Acontext)
        {
            QueryExpression GetLeavedetails = new QueryExpression();
            GetLeavedetails.EntityName = "sgfdhr_leavetype";
            GetLeavedetails.ColumnSet = new ColumnSet("new_type");
            GetLeavedetails.ColumnSet = new ColumnSet("new_availabledays");
            GetLeavedetails.Criteria.AddCondition("new_type", ConditionOperator.Equal,   "Annual" ); //Is this correct????
            GetLeavedetails.Criteria.AddCondition("new_employeeleavecalculation", ConditionOperator.Equal, LeaveDetailsId); //ignore this

            //((OptionSetValue)LeaveDetailsId["new_leavetype"]).Value

            EntityCollection LeaveDetails = _orgService.RetrieveMultiple(GetLeavedetails);
            return LeaveDetails[0];
        }


Please advise.

Thanks, 

Fahad Ali Shaikh

*This post is locked for comments

  • RE: How to Add an optionset filter criteria in MS CRM Query Expression?

    Hi kevin,

    You can check the optionset Value and Text  in the field  properties.

    1_2D00_Division_2D00_Option_2D00_Set.png

    Hope it helps :)

    Thanks ,

  • Kevin T 9 Profile Picture
    Kevin T 9 105 on at
    RE: How to Add an optionset filter criteria in MS CRM Query Expression?

    How do you check which integer value corresponds with a given text value?  Is it assumed you'll figure it out and hard code the value, or is there a way to look up the option set key/value pairs?

  • Guido Preite Profile Picture
    Guido Preite 54,073 Moderator on at
    RE: How to Add an optionset filter criteria in MS CRM Query Expression?

    In your condition you need to set the integer value of the optionset, not the label.

    Assuming that Annual value is for example 2, the code will be:

    GetLeavedetails.Criteria.AddCondition("new_type", ConditionOperator.Equal, 2);

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,430 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans