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

Notifications

Announcements

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,

I have the same question (0)
  • Verified answer
    Alex Fun Wei Jie Profile Picture
    33,628 on at

    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

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    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.

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    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;
                                }
                            }


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

News and Announcements

Season of Giving Solutions is Here!

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 > Dynamics 365 general

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans