Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Embedding WebResource into form

Posted on by

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

  • Verified answer
    efefher Profile Picture
    efefher on at
    RE: Embedding WebResource into form

    Hopefully this helps someone else. I figured out the only reason the table wasn't coming up was because the first request was set to Asynchronous and was taking its time to go through and fetch the information. when I set the last parameter of .open function to false, I was able to make the request synchronous and that made the whole thing work perfectly.

  • Alagunellaikumar Profile Picture
    Alagunellaikumar 6,210 on at
    RE: Embedding WebResource into form

    HI
    Check your browser network status /api/data/v8.1/new_licenses request has 400 error .If it is then put debugger in the code and check what value return in the window.parent.Xrm.Page.context.getClientUrl() and GetGlobalContext().getQueryStringParameters()

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Embedding WebResource into form

    How about when you embed it in Account form?

    Are you getting any of the messages?

  • efefher Profile Picture
    efefher on at
    RE: Embedding WebResource into form

    It all goes perfectly when I run the code in the console.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Embedding WebResource into form

    Can you try adding alert or console.log as below:

    alert("Outside retrieveInfo");
    
        function retrieveInfo()
       {
    
    alert("Inside retrieveInfo");

    The idea is to make sure that your code is being executing. 

    If you get the alert "Ouside retrieveInfo", it means you html web resource is loaded and browser parsed your JavaScript.

    If you get the alert "Inside retrieveInfo", it means your retrieveInfo() method is called on body onload.

    If you don't get any of these alert message, you need to find debug more to find the issue.

    Hope this helps to narrow down the issue.

    Regards,
    Charmis

  • M.T. Eikelenboom Profile Picture
    M.T. Eikelenboom 5,241 on at
    RE: Embedding WebResource into form

    Do you get any errors in the console of the broweser?

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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans