Search code examples
javascriptservicenow

Creating a class on the client side of ServiceNow


I am attempting to develop an API on the client side of service now to access a script include I made on the server side. The API is meant to be callable by client script and eliminate the need for my coworkers to have to use GlideAJAX. At the moment, I have a working script include, but I can't seem to figure out where to put the API such that client scripts are able to call it. Is it possible to do this? Or will my coworkers all have to learn both GlideAJAX and the variables I used in my script include?


Solution

  • Either you make the ui script global and call it like this:

    var myScript = new my_script_id(); //name of the ui script
    myScript.myFunction();
    

    Or you load it with ajax with Scriptloader

    ScriptLoader.getScripts('my_script.jsdbx', function(){
        my_script.myFunction();
    });