Hi
I have web resources as shown in attached file. I have HTML file which is referenced in JS file which is in same place (as shown in Image). If I refernce JS file in HTML Like https://<domain>//WebResources/grid_debugCode However, If i try and do relative path. Somehow it's not working.
How do I give relative path ?
Hi @GLMSDev,
Can you get the full URL instead with method getClientUrl (https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/xrm-utility/getglobalcontext/getclienturl) and load your JS file at run-time with that base URL? Your web resource will be embedded on the form so to reference the Xrm client scripts you'll need window.parent.Xrm.Utility.getGlobalContext(). This way it will be sure to work regardless if on-prem or cloud.
@a33ik This is completely off-topic so I'm happy to move to linkedin messaging or elsewhere but there was definitely a scenario where
./grid_debugCode
worked but
grid_debugCode
didn't and for me to remember it, it must have really, really annoyed me at the time.
Looking at an PCF component I have open on the other screen I wonder if it was to do with file systems as the manifest file has everything as "css/file.css" but the index.ts is "./generated/Manifests" and as I said it really wouldn't surprise me if this is something from 15+ or even 25 years ago but I'm sure it's more recent than that and connected with a CRM project.
I can be wrong but
<script src='./grid_debugCode'></script>
and
<script src='grid_debugCode'></script>
are equal.
Here is what google says to me regarding relative paths - https://www.w3schools.com/html/html_filepaths.asp:
Path | Description |
<img src="picture.jpg"> | picture.jpg is located in the same folder as the current page |
true, but the OP does state in his first post that relative paths weren't working which is why I suggested the absolute path approach
In the back of my mind I seem to remember that the best approach for relative paths is actually
<script src='./grid_debugCode'></script>
(note the additional ./) but I can't remember why I remember that and it could be from the recent past or it could be from NCSA httpd days (yes I am that old) but I think it's far more recent than that.
@ben-thompson with all the respect this is not the perfect solution. It will work fine for IFD and for Online but it will not work for On-Prem because of orgname prepending.
Following should work fine:
<script src='grid_debugCode'></script>
double slashes i.e. // can do very weird things to some web servers.
I suspect if you used
<head>
<script src='/WebResources/grid_debugCode'></script>
</head>
<body onload="myFunction()">
<h1>Hello World!</h1>
</body>
it will work.
Can you please provide url of your html and part of html where you referene your js webresource?
WarrenBelz
87
Most Valuable Professional
mmbr1606
71
Super User 2025 Season 1
Michael E. Gernaey
65
Super User 2025 Season 1