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 optionset value in c#

(0) ShareShare
ReportReport
Posted on by 2,409

Hi, I am trying to case type code through plugin, but I always get this text "Microsoft.Xrm.Sdk.OptionSetValue", how do we get optionset value. I attached the code snippet

 Entity incidentEntity = _orgService.Retrieve("incident", incident(_orgService), new ColumnSet(true));
 string casetype = incidentEntity.Attributes["casetypecode"].ToString();


*This post is locked for comments

  • Saddamk206 Profile Picture
    Saddamk206 777 on at
    RE: how to optionset value in c#

    Hi,

    There are two way to get text of OptionSet:-

    First:-

    OptionSetValue opProductType = new OptionSetValue();

    opProductType = (OptionSetValue)item.Attributes[attributeName];

    var optionValue = opProductType.Value;

    Second:-

    var StatusString = TermAndCon.FormattedValues[attributeName].ToString();

    Post OptionSet Value : -

    newSalesOrder[attributeName] = new OptionSetValue(Convert.ToInt32(optionValue));

  • Suggested answer
  • Verified answer
    Aiden Kaskela Profile Picture
    Aiden Kaskela 19,694 on at
    RE: how to optionset value in c#

    Hi,

    Case the attribute as an OptionSetValue like so:

    ((OptionSetValue)incidentEntity["casetypecode"])

    You can get the option set value on the .Value property (source: msdn.microsoft.com/.../microsoft.xrm.sdk.optionsetvalue.aspx)

    Altogether, the int value for the selected value is

    ((OptionSetValue)incidentEntity["casetypecode"]).Value

    Hope this helps! I'd appreciate if you'd mark this as Answering your question.

    Thanks,

     Aiden

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