How to use custom javascript packages in Service-now ?

Kshitij Tripath
Tera Contributor

We can use single file libraries such jquery.min.js by uploading them in UI script but if there is a directory structure which contains js and css files in separate folders; then how will we use them in SNC ? Examples of such packages can be found on github.

5 REPLIES 5

jfarrer
Mega Guru

There isn't a way to do that within ServiceNow. The best option I know of is to host it on a separate server and reference it.


Hi James,



I tried to use the js files from sample github project by pasting the code in UI scripts and the call was successful from UI pages. Can you please tell how to dynamically reference the js/css files hosted on customer server(linux) under a user's home folder and use them in UI pages ?


Within ServiceNow you can upload CSS files using the Content Management System and then reference them in your UI Page. If you've got them hosted on another server the HTML would be the same in the UI Page but the href attribute would have the full path to the stylesheet (including http).



Here's an article that talks about how to do it:


http://www.servicenowguru.com/content-management/custom-stylesheets-noncms-pages/


Hi James,



Thanks for the quick reply. I was unable to post content due to some failure during posting.



I hosted the javascript package in one of my customer server and was able to call the javascript/css/less files in the UI page.


The below syntax works for calling css and javascript files:


<link href="https://serverurl/webcontainer/css/myfile.css" rel="stylesheet" type="text/css" />


<script>https://serverurl/webcontainer/js/myfile.js" />



The remote server at the customer end should be SSL end otherwise it would throw an error of blocking mixed content - https://developer.mozilla.org/en-US/docs/Security/MixedContent#Mixed_active_content .



In this way, we can use custom javascript frameworks in UI pages without managing them in SNC using UI scripts and keeping the same structure at the remote server end.