Asked by:
How to get the Optionset field text from OData result in ms crm 2011

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()
{
//debugger;
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 + "')";
$.ajax({
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)
{
RetrieveEntityData(data.d);
},
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.
Thanks,
Yadav
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.
thanks,
Yadav
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'
- Edited by Mamatha Swamy Wednesday, September 18, 2013 10:24 PM
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.
http://guruprasadcrm.blogspot.in/2011/07/retrieving-optionset-lable-data-using.html
This is the same link posted my Mamtha.
It should work. What error you are getting?
Thanks!
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.
Thanks,
Yadav
Thursday, September 19, 2013 5:43 AM -
Hi,
If you only need the text from the selected option use...
Xrm.Page.getAttribute("e2sds_sourceofdata").getText()
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.
Chris
Thursday, September 19, 2013 11:38 AM