web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Odata Query not working for CRM Unified Interface but working in Classic UI

(0) ShareShare
ReportReport
Posted on by 432

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

I have the same question (0)
  • Akhil101 Profile Picture
    432 on at

    I debugged the code and found setSrc(url) method not working in APP Interface. Appreciate your help here!

    Xrm.Page.ui.controls.get("IFRAME_itempreview").setSrc(url);

  • Suggested answer
    Mansoor Sulaiman Profile Picture
    4,330 on at

    Hi,

    Pls refer below thread.

    community.dynamics.com/.../232589

    Mansoor

  • Akhil101 Profile Picture
    432 on at

    @Mansoor: Thanks for the response. The function setSrc() is not valid on Unified Interface. Is there any alternate way to set the IFRAME url?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans