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 !
Discover more from Nishant Rana's Weblog
Subscribe to get the latest posts sent to your email.

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