Hello,
I'm trying to embed an html WebResource into the account form. The WebResource is basically triggered onload, it grabs the account id and I'm using soap and fetchxml to grab all the licenses associated to the account to display a table with all the products for that account along with the number of licenses they have. When I run the code on the console it all works perfectly, however when I embed it into the account form using a WebResource or an IFrame the embed shows blank and nothing is displayed. Any suggestions? Using CRM Online 2016 Update 1
<html> <head> <title></title> <script src="../ClientGlobalContext.js.aspx" type="text/javascript"></script> <script type="text/javascript"> function retrieveInfo() { var parameters = GetGlobalContext().getQueryStringParameters(); var html = new Array(); html.push('<table><tr><th>Product</th><th>License Count</th></tr>'); var req = new XMLHttpRequest(); var id = parameters.id; var results; req.open("GET", window.parent.Xrm.Page.context.getClientUrl() + "/api/data/v8.1/new_licenses?fetchXml=%3Cfetch%20version%3D%221.0%22%20output-format%3D%22xml-platform%22%20mapping%3D%22logical%22%20distinct%3D%22false%22%20aggregate%3D%22true%22%20%3E%3Centity%20name%3D%22new_license%22%20%3E%3Cattribute%20name%3D%22new_licenseid%22%20aggregate%3D%22count%22%20alias%3D%22count%22%20%2F%3E%3Cattribute%20name%3D%22new_product%22%20groupby%3D%22true%22%20alias%3D%22product%22%20%2F%3E%3Cfilter%20type%3D%22and%22%20%3E%3Ccondition%20attribute%3D%22new_account%22%20operator%3D%22eq%22%20value%3D%22" + id + "%22%20%2F%3E%3C%2Ffilter%3E%3C%2Fentity%3E%3C%2Ffetch%3E", true); req.setRequestHeader("OData-MaxVersion", "4.0"); req.setRequestHeader("OData-Version", "4.0"); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Prefer", "odata.include-annotations=\"*\""); req.onreadystatechange = function() { if (this.readyState === 4) { req.onreadystatechange = null; if (this.status === 200) { results = JSON.parse(this.response); } else { alert(this.statusText); } } }; req.send(); for (var i = 0; i < results.value.length; ++i) { var line = results.value[i]; var count = line.count; var product = line.product; var prodreq = new XMLHttpRequest(); var prodname; prodreq.open("GET", window.parent.Xrm.Page.context.getClientUrl() + "/api/data/v8.1/products?fetchXml=%3Cfetch%20version%3D%221.0%22%20output-format%3D%22xml-platform%22%20mapping%3D%22logical%22%20distinct%3D%22false%22%3E%3Centity%20name%3D%22product%22%3E%3Cattribute%20name%3D%22name%22%20%2F%3E%3Cfilter%20type%3D%22and%22%3E%3Ccondition%20attribute%3D%22productid%22%20operator%3D%22eq%22%20value%3D%22" + product + "%22%20%2F%3E%3C%2Ffilter%3E%3C%2Fentity%3E%3C%2Ffetch%3E", true); prodreq.setRequestHeader("OData-MaxVersion", "4.0"); prodreq.setRequestHeader("OData-Version", "4.0"); prodreq.setRequestHeader("Accept", "application/json"); prodreq.setRequestHeader("Prefer", "odata.include-annotations=\"*\""); prodreq.onreadystatechange = function() { if (this.readyState === 4) { prodreq.onreadystatechange = null; if (this.status === 200) { prodname = JSON.parse(this.response); } else { alert(this.statusText); } } }; prodreq.send(); html.push('<tr><td>' + prodname.value[0].name + '</td><td>' + count + '</td></tr>'); } html.push('</table>'); document.getElementById("licTable").innerHTML = html.join(""); } </script> </head> <body onload="retrieveInfo()"> <div id="licTable" /> </body> </html>
*This post is locked for comments