Retrieve Option Set text from CRM 2011/2013/2015 in JavaScript

Today I got a requirement to write JavaScript code to get text of the option set value and perform some business validations.
Its really pretty simple to get the option set text from the particular entity and attribute.
We just need to add SDK.Metadata.js reference. This can found under (SDK\SampleCode\JS\SOAPForJScript\SOAPForJScript\Scripts) and use the below code.

function GetOptionSetText(EntityLogicalName, AttributeLogicalName) {

    SDK.Metadata.RetrieveAttribute(EntityLogicalName, AttributeLogicalName, “00000000-0000-0000-0000-000000000000”, true,
       function (result) {
            for (var i = 0; i < result.OptionSet.Options.length; i++) {
                var text = result.OptionSet.Options[i].Label.LocalizedLabels[0].Label;
                var value = result.OptionSet.Options[i].Value;
        function (error) { }

Hope this helps.

Happy CRM’ing

Leave a Reply

Fill in your details below or click an icon to log in: Logo

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

Google photo

You are commenting using your Google 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 )

Connecting to %s