Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Power Apps Pro Dev & ISV
Answered

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 ?

  • EricRegnier Profile Picture
    8,714 Most Valuable Professional on at
    Re: Reference JS file in solution's HTML in Web Resource

    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.

     

     

     

  • Ben Thompson Profile Picture
    1,400 on at
    Re: Reference JS file in solution's HTML in Web Resource

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

  • a33ik Profile Picture
    3,304 Most Valuable Professional on at
    Re: Reference JS file in solution's HTML in Web Resource

    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
    Re: Reference JS file in solution's HTML in Web Resource

    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,304 Most Valuable Professional on at
    Re: Reference JS file in solution's HTML in Web Resource

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

  • a33ik Profile Picture
    3,304 Most Valuable Professional on at
    Re: Reference JS file in solution's HTML in Web Resource

    Following should work fine:

    <script src='grid_debugCode'></script>
  • Verified answer
    Ben Thompson Profile Picture
    1,400 on at
    Re: Reference JS file in solution's HTML in Web Resource

    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. 

  • GLMSDev Profile Picture
    75 on at
    Re: Reference JS file in solution's HTML in Web Resource

    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>

  • a33ik Profile Picture
    3,304 Most Valuable Professional on at
    Re: Reference JS file in solution's HTML in Web Resource

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

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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Leaderboard > Power Apps - Power Apps Pro Dev & ISV

#1
WarrenBelz Profile Picture

WarrenBelz 87 Most Valuable Professional

#2
mmbr1606 Profile Picture

mmbr1606 71 Super User 2025 Season 1

#3
Michael E. Gernaey Profile Picture

Michael E. Gernaey 65 Super User 2025 Season 1

Overall leaderboard