0
votes

I want to query the values from the different Picklist in Opportunity in dynamics CRM 4.0. I don't want to query the actual Opportunity, just the values from the Picklist. So if I have a Picklist called Source and it has the values of 1, 2, 3, 4, 5. I want to query the picklist and get back those values. Is this possible? If so, how in the world do you do it?

I use Java (JAX-WS), but a .NET example is also welcome, due to the use of the same base entities.

What I've tried. I've setup the following query:

// Set up query ...
QueryExpression query = new QueryExpression();
query.setEntityName("picklistmapping");
// Set up columns to retrieve ...
// Add columns to retrieve to the query ...
query.setColumnSet(new AllColumns());

But this query, returns an empty result!

For the record, this is a copy of the following question: Query the Description Value of a Picklist. Difference: that question is about dynamics CRM 2011, mine is about dynamics crm 4.0! The accepted answer of that question says something with the class 'RetrieveAttributeRequest'. Except mine wsdl didn't generate that class, so I guess that's specific for dynamics crm 2011.

1

1 Answers

2
votes

You should use Metadata Service for that purpose. And here is the similar question, where you can find code sample.

RetrieveAttributeRequest attributeRequest = new RetrieveAttributeRequest();
attributeRequest.EntityLogicalName = <your entity name>;
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)
{
    // do something e.g. take o.ValueValue
}