Michael Philip's Blog

Writing about MS Tech with strong focus on Azure & CRM

How TO :Get Text Value of an OptionSetValue Using LINQ in Microsoft Dynamics CRM 2011

Leave a comment

i have been always trying to get the label of an option set value by the way described in the following link https://crmprof.wordpress.com/2013/05/18/how-to-get-the-label-value-for-an-optionset-using-retrieveattribute-request-in-microsoft-dynamis-crm-2011/,  which uses RetrieveAttributeRequest and passing the value which we want to get its label.

CRM 2011 Provides a new way instead of the one described at the link which is using LINQ To CRM Queries.

The basics are as follows. 

1. Use CrmSvcUtil.exe (comes with the SDK) to get a context that you can use with the CRM LINQ provider.

2. Use LINQ to pull the entity attribute FormattedValues for a specific attribute of type OptionSetValue.  The example below is pulling based on a specific entity ID so it pulls the specific text value of the optionset in this instance.

var strstringvalue = (from ca in context.CreateQuery<CampaignActivity>() where ca.ActivityId == campaignResponse.new_CampaignActivityId.Id select ca.FormattedValues[“new_campaignactivitytype”]);


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s