locked
Option set value from crm 2011 RRS feed

  • Question

  • Hello,

    How to get the option set value from an entity in crm 2011 , in windows application. I'm able to insert data into option set from windows application but when user changes option values in crm then again i have to change values in my windows application. So to avoid this, i want to get the contents of option set from crm only. So that when a user changes the option set values, it will be reflected in my application.

    patient["new_registrationtype"] = new OptionSetValue(osv.value);
    The above code shows how i'm inserting the data into option set. I have hard coded the values in combo box and when user selects an option i'll compare and send appropriate values to crm.

    Madhu Sudhan.M

    Friday, August 10, 2012 6:41 AM

Answers

  • Hi Madhu,

    You can use the 'RetrieveAttributeResponse' request:

    RetrieveAttributeRequest retrieveAttributeRequest = new RetrieveAttributeRequest
    {
     EntityLogicalName = "<you entity logical name>",
     LogicalName = "<your attribute>",
     RetrieveAsIfPublished = true
    };
    
    // Execute the request.
    RetrieveAttributeResponse retrieveAttributeResponse = (RetrieveAttributeResponse)_serviceProxy.Execute( retrieveAttributeRequest);
    
    // Access the retrieved attribute.
    PicklistAttributeMetadata retrievedPicklistAttributeMetadata = (PicklistAttributeMetadata) retrieveAttributeResponse.AttributeMetadata;
    
    // Get the current options list for the retrieved attribute.
    OptionMetadata[] optionList = retrievedPicklistAttributeMetadata.OptionSet.Options.ToArray();
    

    hth,

    Scott


    Scott Durow
    Read my blog: www.develop1.net/public
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    • Marked as answer by Madhu-CRM Friday, August 10, 2012 9:43 AM
    Friday, August 10, 2012 7:00 AM
    Answerer

All replies

  • Hi Madhu,

    You can use the 'RetrieveAttributeResponse' request:

    RetrieveAttributeRequest retrieveAttributeRequest = new RetrieveAttributeRequest
    {
     EntityLogicalName = "<you entity logical name>",
     LogicalName = "<your attribute>",
     RetrieveAsIfPublished = true
    };
    
    // Execute the request.
    RetrieveAttributeResponse retrieveAttributeResponse = (RetrieveAttributeResponse)_serviceProxy.Execute( retrieveAttributeRequest);
    
    // Access the retrieved attribute.
    PicklistAttributeMetadata retrievedPicklistAttributeMetadata = (PicklistAttributeMetadata) retrieveAttributeResponse.AttributeMetadata;
    
    // Get the current options list for the retrieved attribute.
    OptionMetadata[] optionList = retrievedPicklistAttributeMetadata.OptionSet.Options.ToArray();
    

    hth,

    Scott


    Scott Durow
    Read my blog: www.develop1.net/public
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    • Marked as answer by Madhu-CRM Friday, August 10, 2012 9:43 AM
    Friday, August 10, 2012 7:00 AM
    Answerer
  • Hello Scott Durow,

    I tried your answer , i'm getting output as {Microsoft.Xrm.Sdk.Metadata.OptionMetadata}.Where i wanted the value in option set. Like if option set is used select type of service then the values will be

    Door Delivery

    Pick Up and Drop

    etc.

    Help me getting the values option set.

    Thank you.


    Madhu Sudhan.M

    Friday, August 10, 2012 8:54 AM
  • I got the answer.

    string selectedOptionLabel = string.Empty;
    foreach (OptionMetadata oMD in optionList) {
    comboBox1.Items.Add(oMD.Label.UserLocalizedLabel.Label);}


    Madhu Sudhan.M


    • Edited by Madhu-CRM Friday, August 10, 2012 9:10 AM
    Friday, August 10, 2012 9:10 AM
  • hi,

    from where did u get  

    optionList..?

    foreach (OptionMetadata oMD in optionList) 


    Please don't forget to Vote and marked as answer If this post answers your question or was helpful, please click "Mark As Answer" on the post and "Mark as Helpful" Be wise

    Friday, August 10, 2012 9:20 AM
  • From Here.

    Madhu Sudhan.M

    Friday, August 10, 2012 9:44 AM
  • Hi scott, i am not using Xrm.sdk. so how i ll get the optionSet value from CRM. I have the same requirement like Madhu. I am using SilverLight App.

    Please suggest something.

    Thank you.


    saroj

    Wednesday, August 22, 2012 11:47 AM