Skip to main content
Community site session details

Community site session details

Session Id : iEPyUAlhWJSKj2bKEwkQWz
Power Pages - Power Apps Portals
Answered

How to import js file to custom javascript

Like (0) ShareShare
ReportReport
Posted on 8 Jan 2022 04:15:33 by Microsoft Employee

Hi all,

 

I'm working on a powerapp task. My app has a 'Page' with a 'Web Form', it has 'Web Form Step' for sure. And I have some logics in the 'Web Form Step' -> 'Custom JavaScript'. 

Now I have an external .js file, which exports some functions I want to import to the 'Custom JavaScript'. I uploaded it to 'Web Files', and named the partial url 'myFileName.js'; I added '<script type="module" src="/myFileName.js"></script>' to 'Web Page' -> 'Content Page' -> 'Content' -> 'Copy (HTML)'.

Then if I added 'import { functionName } from "/myFileName.js";' to 'Web Form Step' -> 'Custom JavaScript', the page will lose all behaviors added by the custom js, so basically the custom js broke down by the 'import' part.

 

Any suggestion for this?

  • oliver.rodrigues Profile Picture
    9,342 Most Valuable Professional on 20 Jan 2022 at 11:19:26
    Re: How to import js file to custom javascript

    @Anonymous the notes file size was originally used for D365 e-mail attachment.. and further functionalities in the system, including Portal Web Files inherited that configuration.

    So basically it's a legacy configuration

  • Community Power Platform Member Profile Picture
    on 19 Jan 2022 at 18:29:45
    Re: How to import js file to custom javascript

    How does email relate to Web Files?

  • oliver.rodrigues Profile Picture
    9,342 Most Valuable Professional on 19 Jan 2022 at 15:16:50
    Re: How to import js file to custom javascript

    You can change the file size from the System Settings - E-mail Tab @Anonymous 

    System Settings Email tab - Power Platform | Microsoft Docs

  • Community Power Platform Member Profile Picture
    on 11 Jan 2022 at 02:23:21
    Re: How to import js file to custom javascript

    How do I upload a large js file to Web Files?

  • joeyzy123 Profile Picture
    Microsoft Employee on 10 Jan 2022 at 19:56:26
    Re: How to import js file to custom javascript

    Hi @OliverRodrigues 

     

    Thanks! I actually tried this before but got error 'function not defined'. Tried again today and it works 😅, maybe I got some typo.

  • Verified answer
    oliver.rodrigues Profile Picture
    9,342 Most Valuable Professional on 10 Jan 2022 at 17:45:50
    Re: How to import js file to custom javascript

    @joeyzy123 usually when importing JS I simply use:

    <script src="/MYJS.js"></script>

    I normally add that to the Tracking Code content snippet.. this way it's loaded on every page, but you can also do that at the page level

     

  • joeyzy123 Profile Picture
    Microsoft Employee on 10 Jan 2022 at 17:43:54
    Re: How to import js file to custom javascript

    Hi @ragavanrajan 

     

    I removed the block for .js file, but the browser console still complains about 'Uncaught SyntaxError: Cannot use import statement outside a module'

  • joeyzy123 Profile Picture
    Microsoft Employee on 10 Jan 2022 at 17:32:51
    Re: How to import js file to custom javascript

    Hi @chleverenz 
    I have to create such a 'library' file because my custom js is reaching the character limits, I will not be able to add any new logic when it's over 10000.


    I checked the browser console as you suggested,:
    Uncaught SyntaxError: Cannot use import statement outside a module

    So I guess the problem is not just the library .js should be a module, but the place where using 'import' should also be module, while 'custom javascript' is not?

  • ragavanrajan Profile Picture
    7,036 Most Valuable Professional on 09 Jan 2022 at 23:23:45
    Re: How to import js file to custom javascript

    Hi @joeyzy123 

     

    Some of the workarounds which I am aware of without unblocking JS extensions. But for this scenario, you need to unblock the JS extension in advanced settings. 

     

    In Portal management: 

    1. Click Settings> Advanced Settings

    2. Under Advanced > settings> System> Administration> System settings 

    3. Remove JS under file extension attachments 

     

     

    ragavanrajan_0-1641770528316.png

    Once done go to the portal studio and sync config and try the web form step. 

     

    Hope it helps. 
    ------------

    If you like this post, give it a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users to find it.

  • Christian Leverenz Profile Picture
    1,214 on 08 Jan 2022 at 13:19:05
    Re: How to import js file to custom javascript

    Hi @joeyzy123 ,

     

    usually, i have a look in browserconsole first, whether there is really a problem. In most cases like this, i see (js) errors in the console and they are usually right.

     

    Do you really need to import the module? I never tried, i always have a plain old js files and use the functions which are in there without any problems. 

     

    In order to leave my personal "die hard" zone i tried also importing stuff recently which failed. The browser complaint(ed?), that the imports have to be on top of the file which is of course not possible in inline js.

     

    May be you could as a workaround create another js fiels and import the functions/module there and use it afterwards.

     

    Hope this points in a solution direction,

      Christian

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

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

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

Leaderboard > Power Pages

#1
Lucas001 Profile Picture

Lucas001 60 Super User 2025 Season 1

#2
Fubar Profile Picture

Fubar 55 Super User 2025 Season 1

#3
surya narayanan Profile Picture

surya narayanan 35

Loading complete