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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

OptionSetValue(Convert.ToInt32()) Not Updating CRM 2016

(0) ShareShare
ReportReport
Posted on by

I am trying to update CRM 2016 via an ASP.Net MVC 4 portal using late binding. I have an Option Set field that i am trying to update using the OptionSetValue(Convert.ToInt32()) but the field does not update.  Below are code snippets of my model and controller.

 

ViewModel:

public class NominatorOrganizationViewModel

{       

   [Display(Name = "Are you submitting this nomination on behalf of an organization?")]       

   public YesOrNoSelectionOrganization OnBehalfOfOrganizationYesOrNo { get; set; }

 

   [Display(Name = "If yes, Nominating Organization:")]

   public string txtOrganization { get; set; }

 

   [DataType(DataType.MultilineText)]

   [Display(Name = "If yes, describe your position in the organization:")]

   public string txtOrganizationPosition { get; set; }

}

Enum values for Yes/No

public enum YesOrNoSelectionOrganization

{

   Nothing = 0,

   Yes = 1,

   No = 2

}

Controller

This code will not work to set the CRM field value

oasys_nomination["oasys_memberofnominatingorganization"] = new OptionSetValue(Convert.ToInt32(NominationVM.NominatorOrganization.OnBehalfOfOrganizationYesOrNo));

 

To work around setting the field, I can use the below code but I don’t think it’s good coding practice and there should be a perfectly good explanation as to why the above code it’s working, I just can’t figure it out.  The code above is similar to other option sets being set throughout the portal but the 1 particular piece of code mentioned above isn’t updating (no errors, just not updating).

 

if (NominationVM.NominatorOrganization.OnBehalfOfOrganizationYesOrNo == YesOrNoSelectionOrganization.Yes)

{

       oasys_nomination["oasys_memberofnominatingorganization"] = new OptionSetValue(2);

}

else if (NominationVM.NominatorOrganization.OnBehalfOfOrganizationYesOrNo == YesOrNoSelectionOrganization.No)

{

        oasys_nomination["oasys_memberofnominatingorganization"] = new OptionSetValue(1);

}

else

{

        oasys_nomination["oasys_memberofnominatingorganization"] = null;

Any ideas?

*This post is locked for comments

I have the same question (0)
  • Gopalan Bhuvanesh Profile Picture
    11,401 on at

    Hi

    Correction-

    I did not notice that YesOrNoSelectionOrganization is enum.

  • Suggested answer
    Gopalan Bhuvanesh Profile Picture
    11,401 on at

    Hi

    oasys_nomination["oasys_memberofnominatingorganization"] = new OptionSetValue(Convert.ToInt32(NominationVM.NominatorOrganization.OnBehalfOfOrganizationYesOrNo));

    Looks correct, for me.

    Did you test the following sets a value to optionset?

    oasys_nomination["oasys_memberofnominatingorganization"] = new OptionSetValue(1);

    and

    oasys_nomination["oasys_memberofnominatingorganization"] = new OptionSetValue(2);

    Please check the value of NominationVM.NominatorOrganization.OnBehalfOfOrganizationYesOrNo, it could be 0, so not setting any value for optionset.

  • Verified answer
    ChrysDW Profile Picture
    on at

    Sometimes, it just takes walking away to realize what the problem is. Thank you everyone for the quick replies but it was very simple and I was overlooking the obvious.  My problem was that I was expecting one result but wasn't checking on the other result. Meaning, my enum YesOrNoSelectionOrganization was configured wrong, it was in the wrong order to what we have in CRM. CRM is configured as No = 1 and Yes = 2.

    //Wrong Configuration

    public enum YesOrNoSelectionOrganization

    {

      Nothing = 0,

      Yes = 1,

      No = 2

    }

    //CorrectConfiguration

    public enum YesOrNoSelectionOrganization

    {

      Nothing = 0,

      No = 1,

      Yes = 2

    }

    Thank you again for the quick replies,

    Chrys

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans