Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 general forum

OptionSet Values Collection C#

(0) ShareShare
ReportReport
Posted on by

I have Custom Entity New_Entity , Which has OptionSet(New_Type) with Values Male and Female (id,100 and 101).

I want to read these values from C# , i need ids in c# code(100,101).

How can i read these values from CRM in C#, Please help

 

Thanks,

  • Suggested answer
    gdas Profile Picture
    50,089 Moderator on at
    RE: OptionSet Values Collection C#

    Hi ,

    You an also write like below -

                            int? type = null;
                            if (_entity.Attributes.Contains("New_Type"))
                            {
                                if (Convert.ToString(_entity.Attributes["New_Type"]) != "" && (_entity.Attributes["New_Type"] as OptionSetValue) != null)
                                {
                                    type = (_entity.Attributes["New_Type"] as OptionSetValue).Value;
                                }
                            }


  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: OptionSet Values Collection C#

    Hi,

    You should be able to get the field value as follows-

    var IndustryOptionSet= (OptionSetValueCollection)targetEntity["new_industry"];

    if(IndustryOptionSet != null)

    {

    var IndustryValue = IndustryOptionSet.Value;

    }

    Hope this help.

  • Verified answer
    Alex Fun Wei Jie Profile Picture
    33,626 on at
    RE: OptionSet Values Collection C#

    Hi,

    you can refer below post.

    Multi select optionset

    community.dynamics.com/.../282806

    docs.microsoft.com/.../multi-select-picklist

    Optionset

    https://community.dynamics.com/crm/f/117/t/250277

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,245 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,925 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans