web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Reference JS file in s...
Power Apps
Unanswered

Reference JS file in solution's HTML in Web Resource

(0) ShareShare
ReportReport
Posted on by 75

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 ?

I have the same question (0)
  • a33ik Profile Picture
    3,306 Most Valuable Professional on at

    Can you please provide url of your html and part of html where you referene your js webresource?

  • GLMSDev Profile Picture
    75 on at

    HTML file

    https://<domain>//WebResources/grid_debugHTML1

     

    JS file

    https://<domain>//WebResources/grid_debugCode

     

    Below is my HTML Code

     


    <script src='https://<domain>//WebResources/grid_debugCode'></script>
    </head>
    <body onload="myFunction()">
    <h1>Hello World!</h1>
    </body>

  • Verified answer
    Ben Thompson Profile Picture
    1,400 on at

    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. 

  • a33ik Profile Picture
    3,306 Most Valuable Professional on at

    Following should work fine:

    <script src='grid_debugCode'></script>
  • a33ik Profile Picture
    3,306 Most Valuable Professional on at

    @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.

  • Ben Thompson Profile Picture
    1,400 on at

    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.

  • a33ik Profile Picture
    3,306 Most Valuable Professional on at

    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:

    PathDescription
    <img src="picture.jpg">picture.jpg is located in the same folder as the current page
  • Ben Thompson Profile Picture
    1,400 on at

    @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.

  • EricRegnier Profile Picture
    8,720 Most Valuable Professional on at

    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.

     

     

     

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard