Skip to main content

Notifications

Community site session details

Community site session details

Session Id : id5mspCrozMRAwh52xWTF/
Power Pages - Power Apps Portals
Unanswered

How to refer Javascript library in Basic Form

Like (0) ShareShare
ReportReport
Posted on 18 May 2022 06:07:14 by 96

I have an advanced form and in one of the advanced form steps, I have a subrid which allows me to add  / edit child records. The subgrid opens a basic form.In this basic form I have some javascript. I also want to refer a javascript libarary (attached as a web-file), and it's functions in this basic form. However, I don't know what's the correct syntex to refer to this library. I tried adding it as 

<script type="text/javascript" src="/commonfunctions.js"></script>
 
but it does not work. Note that this library is also being referenced in the advanced form step. I have no issues on that page because I am referencing the library in the web template for the advanced form.
  • Fubar Profile Picture
    7,885 Super User 2025 Season 1 on 24 May 2022 at 04:47:15
    Re: How to refer Javascript library in Basic Form

    Can't remember if doing it in the Page works or not, but worst case you can dynamically write it via JQuery in the provided JavaScript section

     

     

    var script = document.createElement('script');
    script.src='/yourfile.js';
    script.type = 'text/javascript';
    document.getElementsByTagName('head')[0].appendChild(script);

     

     

     

    You can also probably embed a dataverse Web Resource (that contains the script src tag.) on the entity/basic form

     

    Edit: if script src is in the Web Page content then think it may actually be a scope thing, if inside a document ready try accessing the function using parent.parent.yourfunctionname (or if not in doc ready this.parent.parent.yourfunctioname)

  • Manish R Sharma Profile Picture
    96 on 20 May 2022 at 23:20:35
    Re: How to refer Javascript library in Basic Form

    Hi @OliverRodrigues , I have added it to the web page related to the advanced form, but when I try to call the function from the basic form (modal form on the subgrid of the advanced form), I  get an error:
    Uncaught ReferenceError: CBR is not defined

    I am calling the function like this:

    CBR.Common.dateValidator("cbr_dateofbirth", dateofbirth, "lessthan", today,  "Date of Birth cannot be a future date.");
    If I call this same function on the advanced form step (which has the subgrid), I do not get an error. It seem s that somehow the modal form cannot get the reference of the javascript file from the advanced form web template, or maybe my syntax is wrong. Any suggestions ?
  • oliver.rodrigues Profile Picture
    9,315 Most Valuable Professional on 20 May 2022 at 19:32:26
    Re: How to refer Javascript library in Basic Form

    Hi, how common are these "commongunctions.js"? 

    if they are common throughout all your Advanced Form, I would add this reference to the Web Page related to the Adv Form

    if they are even more high level than that, and would be used your entire Site, I would say to reference in the Content Snippet Tracking Code

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

🌸 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…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Pages - Power Apps Portals

#1
stampcoin Profile Picture

stampcoin 11

#2
Muzammil Nawaz Profile Picture

Muzammil Nawaz 8

#3
Ajlan Profile Picture

Ajlan 6

Overall leaderboard