Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

c# get selected option set text

Posted on by 2,397

Hi, I am trying to get the selected item text from an option set. I got this error:  "The given key was not present in the dictionary"

contact.FormattedValues["registrationcategory"].ToString()


*This post is locked for comments

  • Alex Fun Wei Jie Profile Picture
    Alex Fun Wei Jie 33,626 on at
    RE: c# get selected option set text

    Hi,

    Aric could be right also. just change the prefix in the provided code if he is right.

  • Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: c# get selected option set text

    Are you possibly missing the prefix from the attribute name?

    contact.FormattedValues["new_registrationcategory"].ToString()

  • Verified answer
    Alex Fun Wei Jie Profile Picture
    Alex Fun Wei Jie 33,626 on at
    RE: c# get selected option set text

    Hi,

    i assumed you include this attribute when you select the record.

    Next, check is the optionset value contain data for the selected record?

    if no, you might need to put a checking

    example :

     if (contact.Attributes.Contains("registrationcategory"))

    {

      optionset = contact.FormattedValues["registrationcategory"].ToString();

    }

    Reason :

    if the attribute does not contain data, when you select the record, although you included the attribute, but you will not see the attribute.

  • sdnd2000 Profile Picture
    sdnd2000 2,397 on at
    RE: c# get selected option set text

    I am getting this value from somewhere else

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    Alex Fun Wei Jie 33,626 on at
    RE: c# get selected option set text

    Hi,

    did you include this attribute when you select the record?

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans