How to use - JQuery in UI Page?

goswami_sudipta
Mega Expert

Hello—

Have anyone used JQuery in an UI Page or UI Macro? I would like to understand if there is any plugin which needs to enable to use JQuery; or while creating an UI Page/UI Macro, do I need to include any external link for JQuery?

Please help me out. If you can provide me with an example, that would be much helpful.

Thank you!

Sudipta


CHHAVI SHAHBrad Tilton (Cloud Sherpas)Jim Coyne

1 ACCEPTED SOLUTION

adiddigi
Tera Guru

use $j   - you don't have to include any library from Eureka. jQuery is globally loaded.


View solution in original post

6 REPLIES 6

adiddigi
Tera Guru

use $j   - you don't have to include any library from Eureka. jQuery is globally loaded.


I just removed this script from the HTML.

<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>


then use $j instead of $ for the client script and it is now working both in the form and in the UI page. Thanks a lot!

Raymond Beijerl
Tera Expert

Hi,



Tyler Jones created an excellent article about this: http://jylertones.com/blog/2013/05/the-right-way-to-use-jquery-with-servicenow/



Important is the explaination on $j



Basically, you can add the jquery version that ships with servicenow or you can include you're own



ServicenNow version:



<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="true" xmlns:j="jelly:core" xmlns:g="glide" xmlns:g2="null" xmlns:j2="null">

  <g:requires name="scripts/lib/jquery_includes.js"/>

</j:jelly>


Own version:



Create scripts as UI scripts, then reference from within UI page or in this case i reference the ones hosted at jquery.com


<?xml version="1.0" encoding="utf-8" ?>

<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">



  <meta charset="utf-8"></meta>



  <link rel="stylesheet" href="//code.jquery.com/ui/1.11.0/themes/smoothness/jquery-ui.css"></link>


  <script></script>


  <script></script>


...


</j:jelly>




Raymond


Kalaiarasan Pus
Giga Sage

As abhiram says $j should work out of the box.. Checked that already ? If you want some extra jQuery plugins, follow the approach suggested by Raymond