locked
How to list values from picklist in asp.net RRS feed

  • Question

  • Hi,
    I have account entity. The account has credit card type. and it's a picklist which entered in CRM

    How can i retrieve all the values of credit card type in my asp.net code?

    Appreciate.

    • Edited by Yuhe Friday, June 19, 2009 3:51 PM
    Friday, June 19, 2009 3:23 PM

Answers


  • You will need to use the MS CRM Metadata  service. Please see link below.

    Here is the sample code to retrieve picklist value.
    RetrieveAttributeRequest attributeRequest = new RetrieveAttributeRequest();
    attributeRequest.EntityLogicalName = <Entity Name i.e. contact, account>;
    attributeRequest.LogicalName = <your picklist attribute name>;
    attributeRequest.RetrieveAsIfPublished = true;

    RetrieveAttributeResponse response = (RetrieveAttributeResponse)metaService.Execute(attributeRequest);
    PicklistAttributeMetadata picklist = (PicklistAttributeMetadata)response.AttributeMetadata;


    foreach (Option o in picklist.Options)
    {
        // Get Option value.
    }


    You could also do the same using SQL but I would advise against it.

    Hassan.


    Hassan Hussain | http://hassanhussain.wordpress.com/
    • Proposed as answer by Hassan Hussain Friday, June 19, 2009 3:29 PM
    • Marked as answer by Yuhe Friday, June 19, 2009 3:48 PM
    Friday, June 19, 2009 3:29 PM

All replies


  • You will need to use the MS CRM Metadata  service. Please see link below.

    Here is the sample code to retrieve picklist value.
    RetrieveAttributeRequest attributeRequest = new RetrieveAttributeRequest();
    attributeRequest.EntityLogicalName = <Entity Name i.e. contact, account>;
    attributeRequest.LogicalName = <your picklist attribute name>;
    attributeRequest.RetrieveAsIfPublished = true;

    RetrieveAttributeResponse response = (RetrieveAttributeResponse)metaService.Execute(attributeRequest);
    PicklistAttributeMetadata picklist = (PicklistAttributeMetadata)response.AttributeMetadata;


    foreach (Option o in picklist.Options)
    {
        // Get Option value.
    }


    You could also do the same using SQL but I would advise against it.

    Hassan.


    Hassan Hussain | http://hassanhussain.wordpress.com/
    • Proposed as answer by Hassan Hussain Friday, June 19, 2009 3:29 PM
    • Marked as answer by Yuhe Friday, June 19, 2009 3:48 PM
    Friday, June 19, 2009 3:29 PM
  • Hi, Hesper.

    Use RetrieveAttribute message to retrieve metadata of your picklist attribute against Execute Method of MetadataService. Cast retrieved in response AttributeMetadata to PicklistAttributeMetadata and use it in your code.

    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Friday, June 19, 2009 3:34 PM
    Moderator
  • thanks a lot. It's really helpful.
    Friday, June 19, 2009 3:48 PM