locked
Update Picklist CRM 4.0 IFD RRS feed

  • Question

  • Hi guys

    I am creating a Case from a webservice.

    The case has a custom field which is a PickList, and I am struggeling setting a value for it.
    The user enters some values in a FormView and click Update. The Case creates fine and the Title works fine...but how do I set the Picklist values. And should I set the Int value or the actual string value?

    This is what I tried:

              //Get Values from FormView1
              string caseTitle = FormView1.FindControl("txtTitle").ToString();
              Picklist caseEnquiryType = FormView1.FindControl("txtEnquiryType") as Picklist;
              Picklist caseEnquiryCategory = FormView1.FindControl("txtEnquiryCategory") as Picklist;
    
              myIncident.title = caseTitle;
              myIncident.new_enquirytype = caseEnquiryType;
              myIncident.new_enquirycategory = caseEnquiryCategory;

    Sunday, March 25, 2012 5:12 AM

Answers

All replies

  • Hi Basquiat,

    Have a look at this msdn article with a sample code, there is a section there to set a picklist value from code.

                //   Specify the property name of the DynamicEntity. 
                picklist.Name="preferredcontactmethodcode"; 
                picklist.Value = new Picklist();
    
                //   Set the property's picklist index to 1.
                picklist.Value.Value = 1;
    

    Hope this helps.

    Eric UNG [Senior Analyst Programmer :: Sydney, Australia]

    • Proposed as answer by Damian Sinay Sunday, March 25, 2012 6:59 AM
    Sunday, March 25, 2012 5:48 AM
  • Hi Eric

    Thanks for the reply. Unfortunately it didn't work for me...could you post the link to the article...it might just be something I am missing.

    Sunday, March 25, 2012 11:26 AM
  • Eric, I found the article you were referring to and tried the following without success.

    It does not return any errors but the value doesn't get set either.

           PicklistProperty picklist = new PicklistProperty();
    
        //   Specify the property name of the DynamicEntity. 
              picklist.Name = "new_enquirytype";
              picklist.Value = new Picklist();
    
              //   Set the property's picklist index to 1.
              picklist.Value.Value = 1;

    Sunday, March 25, 2012 11:56 AM
  • Hi Basquiat,

    Could you please paste the entire code here ?

    Sunday, March 25, 2012 12:30 PM
  • Thank you, this is my entire code...

        protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                CrmAuthenticationToken token = new CrmAuthenticationToken();
                token.AuthenticationType = 0;
                token.OrganizationName = "myOrg";
    
                CrmService service = new CrmService();
                service.UseDefaultCredentials = true;
    
                service.CrmAuthenticationTokenValue = token;
                service.Url = ("http://mycrm:5555/mscrmservices/2007/crmservice.asmx");
    
            // Create Case Object
              incident myIncident = new incident();
    
              // Assign Contact / Account      
              Customer objContact = new Customer();
              objContact.type = EntityName.contact.ToString(); 
              objContact.Value = new Guid("{DF1E4CA9-8FEA-E011-9247-00155D018900}"); 
              myIncident.customerid = objContact;
    
              Lookup subjectLookup = new Lookup();
              subjectLookup.type = EntityName.subject.ToString();
              subjectLookup.Value = new Guid("{56DF8306-D315-4CB1-B886-8AA92BD2C4C0}"); 
              myIncident.subjectid = subjectLookup;
    
              //Get Values from FormView1
              string caseTitle = txtTitle.Text;
              myIncident.title = caseTitle;
    
              // Contact PreferredContactMethodCode property
              PicklistProperty picklist = new PicklistProperty();
    
              //   Specify the property name of the DynamicEntity. 
              picklist.Name = "new_enquirytype";
              picklist.Value = new Picklist();
    
              //   Set the property's picklist index to 1.
              picklist.Value.Value = 1;
    
              // Assign Case Status
              myIncident.statecode = new IncidentStateInfo();
              myIncident.statecode.Value = IncidentState.Active;
    
              // Create Incident
              Guid IncidentGuid = Guid.Empty;
    
            Guid incidentId = service.Create(myIncident);
          }
    
            catch (System.Web.Services.Protocols.SoapException ex)
            {
                //Exception handling      
                //throw;  
                throw new Exception(ex.Detail.InnerXml);
            }
    
            catch (Exception)
            {
                //Exception handling         
                throw;
            }
        }

    Sunday, March 25, 2012 3:39 PM
  • Hello,

    It seems that you don't use picklist in your entity creation code. Yes, you've instantiated it but you haven't used it anywhere.


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Follow Andriy on Twitter

    Sunday, March 25, 2012 4:03 PM
    Moderator
  • Thank you...but how exactly do I do that?

    I tried a couple of things, including:

    myIncident.new_enquirytype = picklist.Value;
    Sunday, March 25, 2012 5:07 PM
  • It should be something like

    myIncident.new_enquirytype = new Picklist();
    myIncident.new_enquirytype.Value = <insert int value here>;



    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Follow Andriy on Twitter

    • Marked as answer by Basquiat Sunday, March 25, 2012 7:52 PM
    Sunday, March 25, 2012 6:01 PM
    Moderator