Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 general forum
Answered

OptionSet Values Collection C#

Posted on by Microsoft Employee

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
    gdas 50,083 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
    RaviKashyap 55,406 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
    Alex Fun Wei Jie 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

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

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

Announcing Our 2024 Season 2 Super Users!

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

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,263 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,112 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans