-3

How to get list of data items list from CRM Metadata Source in code behind?

I have a CRm Metadata Source like

<crm:CrmMetadataDataSource ID="dsquestionOptionset" runat="server" EntityName="contact"
     AttributeName="securityquestion"/>

in the html.

I would like to get list of data items in the code behind from the datasource.

"securityquestion" is an intger value and this is linked to an option set.

I tried like

 var listOfItems=dsquestionOptionset.Items;

But not possible

Any help is appreciated

Vinu

Vinu
  • 347
  • 2
  • 7
  • 13
  • I dont really understand what the question is, is the issue with querying Crm or displaying the results in your webpage? – James Wood Aug 09 '12 at 19:43
  • I need all the list of data items of data source as a list to manupulate some functionlaities in the code behind. I would like to get the list of datas as mentioned in the question. Can I have any provision to implement in this way? – Vinu Aug 09 '12 at 19:46

1 Answers1

3

You'll want to query the Metadata. An example (from here: http://msdn.microsoft.com/en-us/library/gg509035.aspx) would be something like:

RetrieveAttributeRequest retrieveAttributeRequest =
    new RetrieveAttributeRequest
{
    EntityLogicalName = Contact.EntityLogicalName,
    LogicalName = "new_picklist",
    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();
Paul Way
  • 1,966
  • 1
  • 13
  • 10
  • Thank you very much for your suggestion. Unfortunately I forgot to mention about the method you have suggested. I would like to implement this thing with a single line of code as shown in the question. Any other suggestion? Vinu – Vinu Aug 09 '12 at 18:56
  • 1
    Sure, wrap this in a function and return the array. – Paul Way Aug 10 '12 at 01:39