Answered by:
Query the Description Value of a Picklist

Question
-
I am trying to get the value from the Description field of a picklist in CRM, this is what I am using to get the Label value, how would I change it to get the Description Value?
RetrieveAttributeRequest request = new RetrieveAttributeRequest(); request.EntityLogicalName = "opportunity"; request.LogicalName = "country"; RetrieveAttributeResponse response = (RetrieveAttributeResponse)orgService.Execute(request); PicklistAttributeMetadata picklist = (PicklistAttributeMetadata)response.AttributeMetadata; foreach (OptionMetadata option in picklist.OptionSet.Options) { string picklistlabel = option.Label.UserLocalizedLabel.Label.ToString(); if (p.Column_16.ToString().ToUpper() == picklistlabel.ToString().ToUpper()) { countryid= option.Value; } }
Thanks!
Saturday, October 15, 2011 7:02 PM
Answers
-
Label Property of OptionMetadata should return you Label
((EnumAttributeMetadata)(picklist)).OptionSet.Options[1].Label.LocalizedLabels[0].Label
HTH
MaKeer | myencounterwithcrm.wordpress.com | CRM2011 User Settings Utility | CRM2011 Lookup Preview- Proposed as answer by Makarand Keer Monday, October 17, 2011 7:29 AM
- Marked as answer by CrazyeD1583 Monday, October 17, 2011 8:18 PM
Saturday, October 15, 2011 9:09 PM
All replies
-
Hello,
As far as I remember following code would return you the description:
string description = picklist.Description.UserLocalizedLabel.Label;
Microsoft CRM Freelancer
My blog (english)
Мой блог (русскоязычный)
Saturday, October 15, 2011 8:12 PMModerator -
Thanks! I think it's close but not quite right. That gives me the Description of the Entity. So if the pick list is called "Country" and the description of the picklist "Country" is "List of Countries" it gives back "List of Countries".
I want to get the Description of the values in the picklist.
So if I have the value in a picklist such as
Label: United States
Value: 1
Description: US
I want to pull back the US.
Thanks!
Saturday, October 15, 2011 8:34 PM -
Label Property of OptionMetadata should return you Label
((EnumAttributeMetadata)(picklist)).OptionSet.Options[1].Label.LocalizedLabels[0].Label
HTH
MaKeer | myencounterwithcrm.wordpress.com | CRM2011 User Settings Utility | CRM2011 Lookup Preview- Proposed as answer by Makarand Keer Monday, October 17, 2011 7:29 AM
- Marked as answer by CrazyeD1583 Monday, October 17, 2011 8:18 PM
Saturday, October 15, 2011 9:09 PM