Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Call HTML webresource on click of a ribbon button.

(0) ShareShare
ReportReport
Posted on by

I have written a HTML webresource to display a subgrid of Documents present in a custom entity(Product Line) as shown in the image below: 

docs1.JPG

This works fine when I add the webresource on the form. But I want this same HTML to be displayed in a new window on click of a ribbon  button . The HTML code is as below:

<html>

<head>
    <title>Account Services</title>
     <!-- <script src="ls_Script_JQuery_1.7.1.min"></script>  -->
    <script src="ClientGlobalContext.js.aspx"></script>
    <script language="javascript" type="text/javascript">		
        function loadAccountServices() {			
            //Get Account Guid
            var account = window.parent.Xrm.Page.getAttribute("pcl_productline").getValue()[0].id;
			var accountId= account.slice(1, -1);
            //Get Account Services
            var accountServices = getAccountServices(accountId);
            if (accountServices != null && accountServices.value.length > 0) {
                var tableData = "";
                for (var i = 0; i < accountServices.value.length; i++) {
                    var service = accountServices.value[i]["pcl_name"];
					var doctype= accountServices.value[i]["pcl_documenttype@OData.Community.Display.V1.FormattedValue"];
                    if (service != null) {
                        //dynamically add table data with Service Names
                        tableData = tableData + "<tr><td>" + service + "</td><td>"+doctype+"</td></tr>";
                    }
                }
                //Create HTML table
                var table = "<table style='font-family:Segoe UI;font-weight:normal;font-size:13px;'><tr style='text-decoration:underline; height:20px'><td>Document</td><td>Document Type</td></tr>' + tableData + '</table>';
                //show table data on the Account form
                window.document.writeln(table);
            }
        }
        //get Account Services
        function getAccountServices(accountId) {
			var req = new XMLHttpRequest();
			req.open('GET', window.parent.Xrm.Page.context.getClientUrl() + '/api/data/v8.2/pcl_documentlists?$select=pcl_documenttype,pcl_name&$filter=_pcl_productline_value eq '+accountId, false);
			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=\'*\'');
			var accountServices = null;
			var temp=null;
			req.onreadystatechange = function() {			
				if (this.readyState === 4) {
					req.onreadystatechange = null;
					if (this.status === 200) {
						
						var results = JSON.parse(this.response);
						accountServices = results;
						for (var i = 0; i < results.value.length; i++) {
							 //accountServices = results[i];
						}
						//return accountServices;
					} else {
						Xrm.Utility.alertDialog(this.statusText);
					}
				}
			};
			
			req.send();
			
			return(accountServices);
			}
        
    </script>
</head>

<body onload='loadAccountServices();'>
</body>

</html>


How should I make this webresource displayed in a new window on click of a ribbon button?

*This post is locked for comments

  • Suggested answer
    RE: Call HTML webresource on click of a ribbon button.

    Hi,

    Hide the Tab from the Form Level under standard Customization. Use the code for the Ribbon Button to set the Custom Screen Visibility 'true'.

    function setTabVisible(){

    Xrm.Page.ui.tabs.get("tab1").setVisible(true);

    }

    Please mark as verified, if you find the answer helpful!

  • Suggested answer
    RE: Call HTML webresource on click of a ribbon button.

    You can use alert.js java script library to achieve this in a very neat and supported way.

    Please read below.

    https://github.com/PaulNieuwelaar/alertjs

    Mansoor

  • Suggested answer
    Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Call HTML webresource on click of a ribbon button.

    Hi,

    You can use openWebResource method from Xrm utility, Check this: https://msdn.microsoft.com/en-in/library/jj602956.aspx?f=255&MSPPError=-2147217396#BKMK_OpenWebResource

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,403 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans