result.Incident_Annotation.length is coming as 0. Can you please review and let me know if any mistake is there?
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/incidents(7a67827b-4242-4cfb-8a0f-d4a867783647)?$expand=Incident_Annotation($select=filename,notetext,subject)", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function() {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);
var incidentid = result["incidentid"];
alert("Hi-->" + result.Incident_Annotation.length);
for (var a = 0; a < result.Incident_Annotation.length; a++) {
var incident_Annotation_filename = result.Incident_Annotation[a]["filename"];
var incident_Annotation_notetext = result.Incident_Annotation[a]["notetext"];
var incident_Annotation_subject = result.Incident_Annotation[a]["subject"];
}
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();