Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Unable to retrieve the selected option set value

Posted on by Microsoft Employee

I have an option set in avd_masteraction entity

schemaName of optionset --> avd_FollowUpRetainOwnerShip

name of option set-->avd_followupretainownership

It has the values

Retain Ownership -->label 100,000,000-->value

Send For Allocation -->label 100,000,001-->value

Depending on the option selected in the option set, i have to change the status field value.

For this i have written the below code.

avd_masteraction newPa = new avd_masteraction();

OptionSetValue subStage = (OptionSetValue)newPa.Attributes["avd_FollowUpRetainOwnerShip"];

int selectedSubStage = subStage.Value;

if (selectedSubStage == (int)avd_masteraction_followupretainownership.SendForAllocation) -->not working

{

newPa.statuscode = new OptionSetValue(avd_masteraction_statuscode.AwaitingAllocation.GetHashCode()); -->this line is working fine

}

if (selectedSubStage == (int)avd_masteraction_followupretainownership.Retain Ownership)

{

newPa.statuscode = new OptionSetValue(avd_masteraction_statuscode.Allocated.GetHashCode());

}

Please tell me where i am going wrong?

*This post is locked for comments

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: Unable to retrieve the selected option set value

    Hi, 
    Try the following code. Hope it works.

    avd_masteraction newPa = new avd_masteraction();

    int selectedSubStage = ((OptionSetValue) entity["avd_followupretainownership"]) .Value; if (selectedSubStage == 100000001) { newPa.statuscode = new OptionSetValue(avd_masteraction_statuscode.AwaitingAllocation.GetHashCode()); } if (selectedSubStage == 100000000) { newPa.statuscode = new OptionSetValue(avd_masteraction_statuscode.Allocated.GetHashCode()); }

    Thanks

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Unable to retrieve the selected option set value

    Hi,

    Try this to retrieve optionset value...

    String text = entity.FormattedValues["yourattributename"].ToString();

    int value = ((OptionSetValue)entity["yourattributename"]).Value;

    Thanks

  • Suggested answer
    shivaram Profile Picture
    shivaram 3,315 on at
    RE: Unable to retrieve the selected option set value

    Hi,

    Try following code for retrieve optionset

    int optValue=newPa.GetAttributeValue<OptionSetValue>("avd_FollowUpRetainOwnerShip").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

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans