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


i have been always trying to get the label of an option set value by the way described in the following Article  which uses RetrieveAttributeRequest and passed the value which we want to get the label for.

CRM SDK Provides another new way instead of the one described in the above 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"]);

How To : Get the Label Value for an OptionSet Using RetrieveAttribute Request in CRM using C# SDK

The following code shows how to to the get label of an option value.


private string GetCRMOptionSetLabel(IOrganizationService service, string entityname, string optionsetname, int value)
RetrieveAttributeRequest reqOptionSet = new RetrieveAttributeRequest();
reqOptionSet.EntityLogicalName = entityname;
reqOptionSet.LogicalName = optionsetname;
RetrieveAttributeResponse resp = (RetrieveAttributeResponse)service.Execute(reqOptionSet);
PicklistAttributeMetadata opdata = (PicklistAttributeMetadata)resp.AttributeMetadata;
var option = opdata.OptionSet.Options.FirstOrDefault(o => o.Value == value);
return option.Label.LocalizedLabels.FirstOrDefault().Label;


How To : Retrieve the Marketing Lists Count Associated With An Event in CRM Using JavaScript

Hi, in this article am gonna show how to retrieve marketing lists count associated with certain event in CRM Using JavaScript.


function retrieveEventAssociatedLists(EventID) {

var listsCount = 0;

var serverUrl = "http://" + document.location.href.split("/")[2];

var ODataPath = serverUrl + "/OrganizationName/XRMServices/2011/OrganizationData.svc";

var retrieveEventListsReq = new XMLHttpRequest();"GET", ODataPath + "/new_new_event_listSet?$filter=new_eventid eq guid'" + EventID + "'",   false);

retrieveEventListsReq.setRequestHeader("Accept", "application/json");

retrieveEventListsReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");


if (retrieveEventListsReq.status == 200) {


var retrievedEventLists = JSON.parse(retrieveEventListsReq.responseText).d;

listsCount = retrievedEventLists.results.length;


return listsCount;


How To : Retrieve Web Resource Contents in CRM using C# SDK

Hi, in this article i am gonna show how to retrieve the content of an "HTML Web Resource" in Microsoft Dynamics CRM using C# SDK

You need to perform 2 steps 

1. perform a "RetrieveMultiple" call to pull back your web resource entity.
2. Decode the "content" property from base-64 to a string.

code :

RetrieveMultipleRequest RetrieveWebResources= new RetrieveMultipleRequest();
RetrieveMultipleResponse resp = new RetrieveMultipleResponse();
Entity webresource = new Entity();

QueryExpression query = new QueryExpression()
EntityName = "webresource",
ColumnSet = new ColumnSet("content"),
Criteria = new FilterExpression
FilterOperator = LogicalOperator.And,
Conditions =
new ConditionExpression
AttributeName = "name",
Operator = ConditionOperator.Equal,
Values = { "web resource name"}

RetrieveWebResources.Query = query;
resp = (RetrieveMultipleResponse)_serviceproxy.Execute(RetrieveWebResources);
webresource= resp.EntityCollection.Entities[0];

byte[] b = Convert.FromBase64String(webresource["content"].ToString());

string strHTML = System.Text.Encoding.UTF8.GetString(b);