The CreatorCon Call for Content is officially open! Get started here.

How to call a non global UI Script?

peterraeves
Mega Guru

I made a UI Script that I want to call from several Client Scripts. When I make the UI Script global, it works and I can find it no problem. But I don't want it to be global obviously. When I put global to false though, it cannot find the class and/or function, so how can I call a non global UI Script?

As example,

UI Script:

var MyClass = Class.create();

MyClass.prototype = {

      initialize: function() {

      },

  myFunction: function(value) {

            return value;

  },

      type: 'MyClass'

};

Client Script:

var value;

new MyClass().myFunction(value);

The above works when it is global, but that doesn't sound right.

3 REPLIES 3

coryseering
ServiceNow Employee
ServiceNow Employee

Hi Peter,



You'll want to use the ScriptLoader, and load your script in those specific places where you need it. I briefly touch on that in this answer:


Re: Unable to create UI Action that calls UI Script in Fuji Scoped Application



The ScriptLoader will load a given UI Script asynchronously, and you can provide a callback that should be executed after the script loads. It sounds like you want to use it in the same way as I described in that answer- load it so that its functions are available later on, when your onChange client scripts are called.


Need syntax example.


G24
Kilo Sage

Is this the answer you were looking for?

UI Script - Global checkbox = false - Application = Global