4

I am facing an problem when I redirect to any HTML webresource.

I have added a HTML page as webresource name "new_My_ProductList" in solution.

I have created a button "Go To My Product" in Ribbon and set following function of JS file as command of it. It will open window.

function RedirectToLowStockList() {
          window.open('WebResources/new_My_ProductList', '_blank', 'scrollbars=1,menubar=no,height=500,width=1000,resizable=1,toolbar=no,status=1');
}

Above function is working perfectly whenever URL is like: "https://mydomain.crm.dynamics.com/WebResources/new_My_ProductList"

But sometimes it generate wrong URL and show Error 404

Here is example of wrong URL:

1- https://mydomain.crm.dynamics.com/_root/WebResources/new_My_ProductList

2- https://mydomain.crm.dynamics.com/_form/WebResources/new_My_ProductList

We can see that there are 2 key word "_root" and "_form" automatically added in URL.

Can anybody please suggest me solution? If above way not appropriate, can anybody please suggest me appropriate solution?

Nanji Mange
  • 2,155
  • 4
  • 29
  • 63

2 Answers2

2

Your ribbon should support the $webresource: directive. From Microsoft's documentation:

When possible, use the $webresource directive. Only references that use the $webresource directive in the site map or ribbon commands will establish dependencies. Dependencies are not created when web resources reference each other.

If you're unfamiliar with editing solution XML, you can install this Ribbon Workbench to help you.

If you're still unsure, you can use Xrm.Utility.openWebResource(webResourceName, webResourceData, width, height). Its use is documented here.

Dave Clark
  • 2,243
  • 15
  • 32
  • Hi Dave, Can you please let me know how to open WebResouce in new windows in `Xrm.Utility.openWebResource()`? Currently it opens in new Tab. – Nanji Mange Mar 14 '17 at 11:50
1

Use the SDK function instead.

Xrm.Utility.openWebResource(webResourceName,webResourceData,width, height)
James Wood
  • 17,286
  • 4
  • 46
  • 89