Retrieve OptionSet Label using SDK.Metadata.RertrieveAttribute method in JavaScript (CRM 2011)


Recently we were working on an HTML Web Resource which was using oData to fetch information regarding a particular entity which had multiple optionset fields in it.

As we know using oData we can get the value of the optionset field but not the label. While searching for the best possible way to get the label in Jscript came to know about the sdk.metadata.js sample code in SDK (sdk\samplecode\js\soapforjscript\soapforjscript\scripts)

It has RetrieveAttribute method in it which can be used to get the attribute metadata

We had an optionset attribute named Language in it, this is how we fetched all the label and the value for that field

var languageArray = [];

// this.RetrieveAttribute = function (EntityLogicalName, AttributeLogicalName, MetadataId, RetrieveAsIfPublished, successCallBack, errorCallBack, passThroughObject
 SDK.Metadata.RetrieveAttribute("new_lawyer", "new_primary_language", null, true, function (result) {

for (var i = 0; i < result.OptionSet.Options.length; i++) {
 languageArray[result.OptionSet.Options[i].Value] = result.OptionSet.Options[i].Label.LocalizedLabels[0].Label;
 function (error) {

Hope it helps !

Cleared MB2-703: Microsoft Dynamics CRM 2013 Customization and Configuration Exam.

Finally took and cleared my first CRM 2013 exam i.e. Customization and Configuration today.

It had total 48 questions in it with passing score of 700.

As expected the main focus area were

  • Access Teams
  • Business Process Flows
  • Business Rules
  • Quick Create forms.
  • New Controls

So anyone planning to take this exam should focus around these new features added in CRM 2013.


Get OptionSet Label using FormattedValues property of Entity in Plugin in CRM

The easiest way to get the Label for the option set in plugin is using the FormattedValues property of the Entity.

The Post Create plugin on Contact record getting the label for the address type field.

if (context.InputParameters.Contains(“Target”) && 
context.InputParameters[“Target”] is Entity){

// Obtain the target entity from the input parmameters. 

Entity entity = (Entity) context.InputParameters[“Target”];


string addressTypeCodeLabel = entity.FormattedValues[“address1_addresstypecode”];

entity.Attributes[“address1_city”] = addressTypeCodeLabel;



Hope it helps.

Using SOAP and OData endpoint of CRM 2013 online in Windows Store App

Connecting to CRM 2013 Online SOAP and OData endpoint through Windows 8 App.

Custom Ribbon Button to get the Guid of the record in CRM 2011

Update :- Works for CRM 2013 as well.


Normally to get the guid we need to click on “Copy a link” button and then get id from the url, so just thought of creating a custom button that only copies the guid.

Clicking on Get Guid button will copy the id to the clipboard


      <CustomAction Id="Sample.all.form.GetGuid.CustomAction"
          <Button Id="Sample.{!EntityLogicalName}.form.GetGuid.Button"
                  Image32by32="/_imgs/ribbon/copyshortcut32.png" />
      <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>
      <CommandDefinition Id="Sample.form.GetGuid">
          <EnableRule Id="Mscrm.FormStateNotNew" />
        <DisplayRules />
          <JavaScriptFunction FunctionName="getGuid"
                              Library="$webresource:new_formActions" >
            <CrmParameter Value="FirstPrimaryItemId" />
      <TabDisplayRules />
      <DisplayRules />
      <EnableRules />
      <LocLabel Id="Sample.all.GetGuid.LabelText">
          <Title languagecode="1033" description="Get Guid" />
      <LocLabel Id="Sample.all.GetGuid.ToolTip">
          <Title languagecode="1033" description="Get the guid of the current record." />

Download the managed solution here ( Change the extension to zip from doc).

Hope it helps.