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 Pages / How to refer Javascrip...
Power Pages
Unanswered

How to refer Javascript library in Basic Form

(0) ShareShare
ReportReport
Posted on 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.
Categories:
I have the same question (0)
  • oliver.rodrigues Profile Picture
    9,368 Most Valuable Professional on at

    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

  • Manish R Sharma Profile Picture
    96 on at

    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 ?
  • Fubar Profile Picture
    8,379 Super User 2025 Season 2 on at

    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)

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 Pages

#1
Fubar Profile Picture

Fubar 89 Super User 2025 Season 2

#2
Jerry-IN Profile Picture

Jerry-IN 75

#3
sannavajjala87 Profile Picture

sannavajjala87 31

Last 30 days Overall leaderboard