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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

CRM web form: DropDownList value has 'Incorrect Attribute' error for Option Set

(0) ShareShare
ReportReport
Posted on by

We have created web services that provide the values of the custom option sets in our Lead entity. These are called into dropdownlists on an asp.net web form;

 

WebSvc.WcfSvcClient enq_wsvc = new WebSvc.WcfSvcClient();

Dictionary<Int64, string> genderData = new Dictionary<Int64, string>();

genderData = enq_wsvc.GetGender();

genderDropDown.DataSource = genderData.Values;

genderDropDown.DataBind();

genderDropDown.Items.Insert(0, new ListItem("", "-1"));

 

We then pass this back via on the button click event;

 

newLead.gender = genderDropDown.SelectedItem.Text;

enq_wsvc. SetLead(newLead);

 

Using the OperationContract / DataContract method;

 

[DataMember]

       public string gender

       {

           get { return genderDropDown; }

           set { genderDropDown = value; }

       }

To then finally have the CRM web service create the new record;

lead["uoc_gender"] = newLead.gender.ToString();

Guid newLeadId = myCRMService.Create(lead);

 

This works for all the ‘Single Line of Text’ formatted fields on the form, but does not work this option set, giving me the following error;

 

Incorrect attribute value type System.String

 

I can step through the code and see the values being brought over prior to the .Create(lead) so I’m stumped. I haven’t been able to find any guidance on how to do this via dropdownlists/webservices despite a lot of looking and failed testing.

Am I right in thinking that is because I’m trying to update an option set field, and if so how does this differ from trying to update a standard text field?

 

Any help massively appreciated. Thanks

*This post is locked for comments

I have the same question (0)
  • Aileen Gusni Profile Picture
    44,524 on at
    RE: CRM web form: DropDownList value has 'Incorrect Attribute' error for Option Set

    Thomas.

    Good.

    Thanks.

  • Thom Profile Picture
    on at
    RE: CRM web form: DropDownList value has 'Incorrect Attribute' error for Option Set

    Hi both, the web service somehow stopped being 'seen' by the web form. Removed and reinstated this with the suggestions you provided and on testing the option sets (ALL OF THEM) are now updating. Thank you SO much for your help.

  • Royal King Profile Picture
    27,686 on at
    RE: CRM web form: DropDownList value has 'Incorrect Attribute' error for Option Set

    you have to convert selected value into integer, try with below code

    newLead.gender =Int32.Parse(genderDropDown.SelectedValue) ;

  • Thom Profile Picture
    on at
    RE: CRM web form: DropDownList value has 'Incorrect Attribute' error for Option Set

    Hi both

    Sorry for the late response. I've been on leave. So have tried and getting this error on the web form;

    newLead.gender = genderDropDown.SelectedValue;

    Cannot implicitly convert type 'string' to 'int'

    I have added this to the genderDropDown setup as it wasn't bringing over the value, but now its throwing the error above before build;

    Dictionary<Int64, string> genderData = new Dictionary<Int64, string>();

    genderData = enq_wsvc.GetGender();

    genderDropDown.DataTextField = "Value";

    genderDropDown.DataValueField = "Key";

    genderDropDown.DataSource = genderData;

    genderDropDown.DataBind();

    genderDropDown.Items.Insert(0, new ListItem("", "-1"));

    This is getting really frustrating now so any help is massively appreciated.

  • Thom Profile Picture
    on at
    RE: CRM web form: DropDownList value has 'Incorrect Attribute' error for Option Set

    Apologies Aileen / Chitra, that error was on another dropdownlist. I think my issue is that the optionset value is not being registered when databinding to the dropdownlist. Am I right in thinking that I need to bring over both the Label (to have the as an item to select) and the MetadataId (which serves as the integer value for that field)?

  • Aileen Gusni Profile Picture
    44,524 on at
    RE: CRM web form: DropDownList value has 'Incorrect Attribute' error for Option Set

    Thomas,

    How you bind the dropdown list?

    And getting this 2012/3?

    If your Gender Option Set is 1 for female and 2 for male, for example, then you need to bind the DDL as same as it is.

    Thanks.

  • Verified answer
    Royal King Profile Picture
    27,686 on at
    RE: CRM web form: DropDownList value has 'Incorrect Attribute' error for Option Set

    The string value "2012/3" is not a valid integer value. You have to pass integer value of the gender code to the option set value.

  • Aileen Gusni Profile Picture
    44,524 on at
    RE: CRM web form: DropDownList value has 'Incorrect Attribute' error for Option Set

    Hi Thomas,

    Ok if like that, try to keep the datacontract to string and change the code to this:

    lead["uoc_gender"] = new OptionSetValue(Convert.ToInt32(newLead.gender.ToString()));

    Thanks.

  • Thom Profile Picture
    on at
    RE: CRM web form: DropDownList value has 'Incorrect Attribute' error for Option Set

    Hi Aileen

    Thanks for getting back to me so quickly. I have tested this and it’s definitely feels like the right direction, but I’m getting the following error.

     

    ProtocolException was unhandled by user code

    The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:newLead. The InnerException message was 'There was an error deserializing the object of type UoC.CRM.Courses.WcfSvc.FormFields. The value '2012/3' cannot be parsed as the type 'Int32'.'. Please see InnerException for more details.

     

    In the [DataContract] I declared the drop down as an Int32;

    Int32 genderDropDown;

     

    With the [DataMember] configured like this;

    public Int32 gender

           {

               get { return genderDropDown; }

               set { genderDropDown = value; }

           }

     

    I’m guessing it’s something to do with the dropdownlist containing only the values of the option sets, so it can’t reference the id of that value when returning it to the web service. Or am I way off? :)

  • Royal King Profile Picture
    27,686 on at
    RE: CRM web form: DropDownList value has 'Incorrect Attribute' error for Option Set

    You have to pass Option set value type not string. Use below code that should fix this issue

    lead["uoc_gender"] =new OptionSetValue( gender integer value);//  newLead.gender.ToString();

    Guid newLeadId = myCRMService.Create(lead);

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#2
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans