How to get the Optionset field text from OData result in ms crm 2011 RRS feed

  • Question

  • Hi,

    I am retrieving the Opportunity record data from Quote entity. I am getting the Opportunity record optionset value in OData result set. But I need Optionset Text. How to get this optionset text from this OData result set. Below is my code.

    function GetOpportunityData()
      var opplookup = Xrm.Page.getAttribute("opportunityid").getValue();
      if(opplookup[0] != null)
         var opplookupguid = opplookup[0].id;
         var serverUrl =document.location.protocol + "//" + document.location.host + "/" + Xrm.Page.context.getOrgUniqueName();
         var odataSelect = serverUrl + "/XRMServices/2011/OrganizationData.svc/OpportunitySet(guid'" + opplookupguid + "')";    
     type: "GET",
     contentType: "application/json; charset=utf-8",
     datatype: "json",
     url: odataSelect,
     beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); },
     success: function (data, textStatus, XmlHttpRequest)
     error: function (XmlHttpRequest, textStatus, errorThrown) { alert('OData Select Failed: ' + odataSelect); }


    function RetrieveEntityData(Entity)
     // get the fields from the Entity object
     var optValu = (eval(Entity.StatusCode.Value));// Here getting the Optionset value


    Please provide the sample code how to get the text from this result in OData.



    Wednesday, September 18, 2013 6:47 PM

All replies

  • Hi,

    I tested as you mentioned. But its not working.

    Please let me know is there any workaround for this.



    Wednesday, September 18, 2013 7:39 PM
  • Check out this blog.

    If my response helps you in finding your answer then please click 'Mark as Answer' and 'Vote as Helpful'

    Wednesday, September 18, 2013 10:23 PM
  • Hi,

    Odata returns only optionset Value. You will have to Get The Odata Value and Retrieve the Optionset attribute metadata and get the text for the value.


    This is the same link posted my Mamtha.

    It should work. What error you are getting?


    Thursday, September 19, 2013 5:17 AM
  • Hi,

    Thanks for your reply. I am getting the error while executing the following method.

    SDK.MetaData.RetrieveEntityAsync(SDK.MetaData.EntityFilters.Attributes, entityLogicalName, null, false, function (entityMetadata) { successRetrieveEntity(entityLogicalName, entityMetadata, RetrieveAttributeName, stateValue, AssignAttributeName); }, errorDisplay

    How to customize the above method to work.Please let me know the required changes in this method.



    Thursday, September 19, 2013 5:43 AM
  • Hi,

    If you only need the text from the selected option use...


    If you are wanting all available options you will have to use metadata retrieve.

    Alternatively you can interrogate the dom object, however this is not supported, and won't show you all available options if some have been filtered out.


    Thursday, September 19, 2013 11:38 AM