The CreatorCon Call for Content is officially open! Get started here.

What is the right way to include jquery.min.js and jquery-ui.min.js in a UI Page and UI Script

Sebastian Gonz2
Giga Contributor

As mentioned in the title I am trying to add jquery to my UI Page.

I was able to add jquery.min.js to the UI Page with a <script>https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> tag, but I cannot call any jquery in UI Scripts linked to this UI Page, I get errors like "$ is not a function". (Could it be and issue with the namespace since I'm in a scoped application?).

Also I cannot load the User Interface jquery-ui.min.js in either the UI Page or the UI Script. I have tried loading it with a <script> tag at the top of the UI Page and by putting the <script> tag in a UI Macro and then doing a <g:macro_invoke> in the UI Page, but neither version worked.

Any help would be appreciated.

6 REPLIES 6

ghsrikanth
Tera Guru

Have you tried this -


<g:requires name="scripts/lib/jquery_includes.jsx" includes="true" />


Srikanth,



As far as I know <g:requires> is used to add existing UI Scripts to UI Macros or Pages, I was trying to avoid copying the source code for jquery and creating a UI script so I could call it.


AJ Siegel
ServiceNow Employee
ServiceNow Employee

Sebastian,



When you look at the network tab or resources tab in Inspect Element, do you see the jQuery.js getting loaded? You may need to run jquery in noconflict mode, https://jylertones.com/blog/2013/05/the-right-way-to-use-jquery-with-servicenow/



Good luck!


Andrew,



Seems to be loading OK, but I still get the error messages. I will try noconflict mode, thanks.