Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

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

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

  • Akhil101 Profile Picture
    Akhil101 432 on at
    RE: Odata Query not working for CRM Unified Interface but working in Classic UI

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

  • Suggested answer
    Mansoor Sulaiman Profile Picture
    Mansoor Sulaiman 4,330 on at
    RE: Odata Query not working for CRM Unified Interface but working in Classic UI

    Hi,

    Pls refer below thread.

    community.dynamics.com/.../232589

    Mansoor

  • Akhil101 Profile Picture
    Akhil101 432 on at
    RE: Odata Query not working for CRM Unified Interface but working in Classic UI

    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);

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans