How do I get the text for an optionset value from a CRM Query? Here is how I have written my query:
function nearByCases(addr){
var nearByCasesFetchXML = '<fetch distinct="false" mapping="logical" output-format="xml-platform" version="1.0">' +
'<entity name="incident">' +
'<attribute name="title"/>' +
'<attribute name="ticketnumber"/>' +
'<attribute name="createdon"/>' +
'<attribute name="new_department"/>' +
'<attribute name="new_casetype"/>' +
'<attribute name="incidentid"/>' +
'<attribute name="caseorigincode"/>' +
'<order descending="false" attribute="title"/>' +
'<filter type="and"><condition attribute="new_address" value="'+addr+'" operator="eq"/>' +
'</filter>' +
'</entity>' +
'</fetch>';
nearByCasesFetchXML = "?fetchXml=" + encodeURIComponent(nearByCasesFetchXML);
var html = "";
//var outputText = "Case\t\t\tCreated\n---------------------------------------------------\n";
window.parent.Xrm.WebApi.retrieveMultipleRecords("incident", nearByCasesFetchXML).then(function success(result) {
console.log(result.entities);
if(result.entities.length <=0) {
window.parent.Xrm.Utility.alertDialog("No results found.", null);
return false;
}
else{
for (var casecount = 0; casecount < result.entities.length; casecount++) {
// outputText += result.entities[casecount].ticketnumber+ "\t\t" + result.entities[casecount].title + "\n";
html += "<tr>";
html += "<td>"+result.entities[casecount].title+"</td>";
html += "<td>"+result.entities[casecount].ticketnumber+"</td>";
html += "<td>"+result.entities[casecount].FormattedValues["new_department"].ToString()+"</td>";
html += "<td>"+result.entities[casecount].new_casetype+"</td>";
html += "</tr>";
$("#nearbycases tbody").html(html);
}
return true;
}
//window.parent.Xrm.Utility.alertDialog(outputText, null);
},function (error) {
// Handle error conditions
window.parent.Xrm.Utility.alertDialog(error.message, null);
});
}
This is fetchXml to fetch the data from incident
and I am able to get all incident values but there are some custom optionsets (new_department
,new_casetype
) which only return the value, not the text.
So how do I get the text of these option set.
This is the response I get
{ "@odata.etag": "W/"1999118"" , "createdon": "2018-12-13T08:30:34Z" , "[email protected]": "12/13/2018 2:30 AM" , "incidentid": "dedfb05b-b1fe-e811-a977-000d3a33eb4e" , "new_casetype": 1 , "[email protected]": "Abandoned Vehicles" , "new_department": 1 , "[email protected]": "Parking Control" , "ticketnumber": "CAS-01001-H2S7L9" , "title": "case for sla 1", }