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

Hi,

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) {
 alert("error");
 }
 );

Hope it helps !


Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

1 thought on “Retrieve OptionSet Label using SDK.Metadata.RertrieveAttribute method in JavaScript (CRM 2011)”

Share your thoughts

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s