Hi All,
I am trying to load notes attachments in an IFRAME using Javascript. This seems to be working fine in the classic UI but I am not getting any response when using Unified App Interface.
Below is the code:
function GetRecordAttachments(recordId) {
recordId = recordId.replace('{', '');
recordId = recordId.replace('}', '');
var viewInBrowser = ["image/png", "text/plain", "application/pdf", "image/jpg", "image/jpeg", "image/bmp"];
var globalContext = Xrm.Utility.getGlobalContext();
var serverUrl = globalContext.getCurrentAppUrl();
var req = new XMLHttpRequest();
req.open("GET", serverUrl + "/api/data/v8.0/annotations?$select=annotationid,documentbody,filename,mimetype,subject&$filter=_objectid_value eq " + recordId + " and isdocument eq true", 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=\"OData.Community.Display.V1.FormattedValue\"");
req.onreadystatechange = function () {
alert("Inside Req");
if (this.readyState === 4) {
alert("Ready State:" + req.readyState);
req.onreadystatechange = null;
alert("Status:" + req.status);
if (this.status === 200) {
alert("this.response:" + req.response);
var results = JSON.parse(this.response);
alert("Results:" + results);
for (var i = 0; i < results.value.length; i++) {
var annotationid = results.value[i]["annotationid"];
var documentbody = results.value[i]["documentbody"];
var filename = results.value[i]["filename"];
var mimetype = results.value[i]["mimetype"];
var subject = results.value[i]["subject"];
alert("annotationid:" + annotationid);
alert("documentbody:" + documentbody);
alert("filename:" + filename);
alert("mimetype:" + mimetype);
alert("subject:" + subject);
var url = "data:" + mimetype + ";base64," + documentbody;
alert("url:" + url);
var id = "h" + i;
var Isview = false;
for (var j = 0; j < viewInBrowser.length; j++) {
if (viewInBrowser[j] == mimetype) {
Isview = true;
break;
}
}
alert(Isview);
if (Isview) {
Xrm.Page.ui.controls.get("IFRAME_itempreview").setSrc(url);
$("#IFRAME_itempreview").contents().find(".change-class").css('background-color', 'black');
}
}
}
else {
alert(this.statusText);
}
}
};
req.send();
}
Regards,
AKHIL
*This post is locked for comments