Can you call a script include from a client script - without GlideAjax?

asd13
ServiceNow Employee
ServiceNow Employee

This is more of a curiosity question rather than trying to solve a particular problem and I know best practice says always use ajax, yada yada.   I was just trying to test a simple class create SI from a client script and thought I could declare and call the SI function without the ajax gubbins but I haven't had any joy.   The SI call works as expected from server-side script so it's not syntax related - and the SI is client-callable.   There are also a bunch of standard client-callable SI's which ship as standard... so


do I need to use GlideAjax with a SI I want to access client-side?


thanks!

David

1 ACCEPTED SOLUTION

Hi David, actually in that thread I later mention i was wrong and confirmed that it's true that from the client you can only call a script include through a GlideAjax. The good news (in a way )... is that you have an alternative which is to use an asynchronous Glide Record to perform the same query you have in the script include.



Thanks,


Berny


View solution in original post

9 REPLIES 9

The SN Nerd
Giga Sage
Giga Sage

do I need to use GlideAjax with a SI I want to access client-side?




No.



If you are looking to re-use client side code, you can create UI Scripts.



UI Scripts - ServiceNow Wiki


UI scripts provide a way to package client-side JavaScript into a reusable form, similar to how script includes store server-side JavaScript. Administrators can create UI scripts and run them from client scripts


and other client-side script objects and from HTML code.




If you are looking at retrieving data from the server (such as database queries) you should use GlideAjax if you want a maintainable ServiceNow instance.



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

asd13
ServiceNow Employee
ServiceNow Employee

Thanks Paul for the UI Scripts pointer - I'll check them out.   Just to play devils advocate though - is it possible to call an SI client side? (without ajax)


bernyalvarado
Mega Sage

Hi David, the following thread might be useful:



Re: How can I make a Script Inclide available for a client script without the ajaxcall ?



Thanks,


Berny


asd13
ServiceNow Employee
ServiceNow Employee

Thanks Berny.   I had a read through and you mention using a classless script include (getTableExtensions).   I tried calling that as below:



var myObj = 'task';
var foo = new getTableExtensions(myObj);
alert("Returned list is " + foo);


but I get a


ReferenceError: global is not defined



I get the same if I strip off the global.   Have I mis-understood or am I using incorrectly?




cheers


Dave