Get value for OptionSet in CRM 2011

To get the value for OptionSet we can use the following function

string GetOptionsSetTextOnValue(IOrganizationService service, string entityName, string attributeName, int selectedValue)

RetrieveAttributeRequest retrieveAttributeRequest = new

EntityLogicalName = entityName,

LogicalName = attributeName,

RetrieveAsIfPublished = true

// Execute the request.

RetrieveAttributeResponse retrieveAttributeResponse =(RetrieveAttributeResponse)
// Access the retrieved attribute.

Microsoft.Xrm.Sdk.Metadata.PicklistAttributeMetadata retrievedPicklistAttributeMetadata =(Microsoft.Xrm.Sdk.Metadata.PicklistAttributeMetadata)

retrieveAttributeResponse.AttributeMetadata;// Get the current options list for the retrieved attribute.
OptionMetadata[] optionList =
string selectedOptionLabel = string.Empty;

foreach (OptionMetadata oMD in optionList)
if (oMD.Value == selectedValue)
{selectedOptionLabel = oMD.Label.UserLocalizedLabel.Label;


return selectedOptionLabel;



Hope it helps !

Using OrganizationServiceClient in CRM 2011

 Add Service Reference to the Organization WCF service in the application.

URL àhttp://servername:port/OrganizationName/xrmServices/2011/organization.svc 

Use the following code to perform various functions using OrganizationServiceClient 

Entity myContact = new Entity();

myContact.LogicalName = “contact”; 

AttributeCollection myAttColl = new AttributeCollection();

myAttColl.Add(new KeyValuePair<string, object>(“lastname”, “Rana”));

myContact.Attributes = myAttColl;
ClientCredentials credentials = new ClientCredentials();

Uri organizationUri = new Uri(http://servername:port/organizationname/xrmServices/2011/organization.svc&#8221;);

OrganizationServiceClient orgClient = new OrganizationServiceClient();

orgClient.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential(“username”, “password”, “domain”); 


catch (Exception ex)

throw ex;


Hope it helps.

CRM Shortcut in CRM 2011 Dialogs

Hi I was just wondering how we can use CRM Shortcut radio button option that appears in Insert Hyperlink dialog box of Dialogs in CRM 2011.

After searching for it, I found the following post which says that we should ignore that button as it won’t be there in the final release.

Hope it helps !

Adding Left Navigation Item to a form in CRM 2011


Export solution containing the entity we need to modify.

Find the <form> tag for the form we want to modify within <FormXml> tag

Then use the following sample xml to add the left navigation item.

<NavBarItem Id=”navItemID1″ PassParams=”1” Area=”Info” Icon=”testIcon” Url=”“>
<Title LCID=”1033” Text=”Custom Nav Item”/>


Dynamic Values in Workflow in CRM 4

We were facing an issue today; the issue was something like this

We were sending mail in one of our workflow, in the to field of the workflow we had set multiple users name as dynamic values. But we found that mail was being sent to only one user, i.e. the first user only.

Than we found out that if we add multiple values in Look For dialog box and click on ok to add all those together, only the first field having value would be picked by workflow.

For e.g. if I add (created by), (manager of the user field) in the look for dialog box and click on ok to add them together, the workflow would only pick the value for first field i.e. (created by) field for which value exists. It would ignore the manager of the user field. 

However if we add them separately i.e. first add (created by) field and then look for (manager of the user field) and add that field than we could have values for both the field. 


Making value in one lookup depended on value of another lookup.

Making value in one lookup depended on value of another lookup in Microsoft CRM. Say we have created 2 custom entities Categories and Skill. Skill entity has category lookup field which relates it to that category.(Added a relationship between them)Than created few records for both the entities. After that we have added that entities to the third entity where they’ll appear as LookUp.

Now we want the value of Skill lookup to be dependent value selected on Resource(Category) LookUp.


Resource can have following values


Now if Datawarehousing is selected than

we want to show Analysis and SSAS in the Skill lookup


To accomplish this we will write the following code in the OnChange event of Resource Lookup

// Making the skill id lookup null whenver a new values is selected for reesource


crmForm.all.new_skillid.disabled = false;

// getting the value of selected resource

var ar=new Array();


var rID = ar[0].id;

// Changing the display of skillid lookup so that only skill belonging to particular rID should appear


// in the additionalparams for the skill id attribute we will specify the fetch xml query // e.g. select * from new_categoryskill (name of our custom skill entity) where new_categoryofskillid = rid

crmForm.all.new_skillid.additionalparams = “fetchXml=<fetch mapping=’logical’ ><entity name=’new_categoryskill’><all-attributes/><filter type=’and’><condition attribute=’new_categoryofskillid’ operator=’eq’ value='” + rID + “‘/></filter></entity></fetch>”;

To get the fetchXml query what we can do over here is

We will go to our skill entity form and run an advancedfind query against it (giving the appropriate condition for which we want the fetch xml)

Now pressing CTRL+N open it in a new window Now in URl replace everything with the following line


Press Ok to the dialog that appears and it opens a prompt window from where we can copy our fetch xml and modify it accordingly.

%d bloggers like this: