Service Portal not recognizing jQuery library

jpavanaryan
Tera Expert

I am trying use jQuery DataTable with Angular JS in ServiceNow application and it throws following error jQuery(...).DataTable is not a function. Created variable 'j' to avoid conflict between jQuery and AngularJS.

Screen Shot 2017-04-20 at 12.39.11 PM.png

1 ACCEPTED SOLUTION

I used the setup I described above with the basic example from the dataTables.net site and it worked for me.



data_table.png


Client Controller:


function() {


 


  var c = this;


  $("#example").dataTable({


  "aaData":[


  ["Sitepoint","http://sitepoint.com","Blog","2013-10-15 10:30:00"],


  ["Flippa","http://flippa.com","Marketplace","null"],


  ["99designs","http://99designs.com","Marketplace","null"],


  ["Learnable","http://learnable.com","Online courses","null"],


  ["Rubysource","http://rubysource.com","Blog","2013-01-10 12:00:00"]


  ],


  "aoColumnDefs":[


  {


  "sTitle":"Site name",


  "aTargets": [ "site_name" ]


  },


  {


  "aTargets": [ 1 ],


  "bSortable": false,


  "mRender": function ( url, type, full )   {


  return   '<a href="'+url+'">' + url + '</a>';


  }


  },


  {


  "aTargets":[ 3 ],


  "sType": "date",


  "mRender": function(date, type, full) {


  return (full[2] == "Blog") ? new Date(date).toDateString(): "N/A" ;


  }


  }


  ]


  });



}



HTML :


<div>


  <table id="example">


      <thead>


          <tr><th class="site_name">Name</th><th>Url </th><th>Type</th><th>Last modified</th></tr>


      </thead>


      <tbody>


          <tr><td>SitePoint</td></tr>


          <tr><td>Learnable</td></tr>


          <tr><td>Flippa</td></tr>


      </tbody>


  </table>


</div>


View solution in original post

6 REPLIES 6

ChrisBurks
Giga Sage

By your screenshot it looks like you're trying to bring in your jquery styles and script library by using the <link> and <script> tags within the widget.


You should bring in outside libraries through the js and css includes in your Theme modules under the Service Portal application.



Navigate to Service Portal > Theme


Then select the Theme you are using for your portal.


At the bottom of the Theme form select the CSS includes or JS includes tab respective to the type of file to be included


Click "New"


Since it looks like you're using a CDN for the Source field select "URL"


Enter your source PATH


Give it a name


Click "Submit"



Now your external source files should be loaded with your Portal automatically.




getting_to_theme.png



include_tabs.png



css_include.png


js_include.png


Hello Chris,


That was my first try. It didn't work.


For Service Portal you don't need to setup a "no conflict".   So you should be able to just use $() syntax.


I used the setup I described above with the basic example from the dataTables.net site and it worked for me.



data_table.png


Client Controller:


function() {


 


  var c = this;


  $("#example").dataTable({


  "aaData":[


  ["Sitepoint","http://sitepoint.com","Blog","2013-10-15 10:30:00"],


  ["Flippa","http://flippa.com","Marketplace","null"],


  ["99designs","http://99designs.com","Marketplace","null"],


  ["Learnable","http://learnable.com","Online courses","null"],


  ["Rubysource","http://rubysource.com","Blog","2013-01-10 12:00:00"]


  ],


  "aoColumnDefs":[


  {


  "sTitle":"Site name",


  "aTargets": [ "site_name" ]


  },


  {


  "aTargets": [ 1 ],


  "bSortable": false,


  "mRender": function ( url, type, full )   {


  return   '<a href="'+url+'">' + url + '</a>';


  }


  },


  {


  "aTargets":[ 3 ],


  "sType": "date",


  "mRender": function(date, type, full) {


  return (full[2] == "Blog") ? new Date(date).toDateString(): "N/A" ;


  }


  }


  ]


  });



}



HTML :


<div>


  <table id="example">


      <thead>


          <tr><th class="site_name">Name</th><th>Url </th><th>Type</th><th>Last modified</th></tr>


      </thead>


      <tbody>


          <tr><td>SitePoint</td></tr>


          <tr><td>Learnable</td></tr>


          <tr><td>Flippa</td></tr>


      </tbody>


  </table>


</div>