The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Use of a common JavaScript file in ServiceNow.

dev115415
Tera Expert

Hello

I want to use a common JavaScript file for my UI Pages in ServiceNow.

Let us say I have 5 UI Pages where I want to handle the button click event. So presently I have to write the JavaScript logic for each file every time in Client Script present underneath UI Page.

dev115415_0-1685893887087.png

Is there any way to use a common Client Script in each UI Page instead of writing them separately. In normal JavaScript we were using <script src="myscripts.js"></script> for example.

3 REPLIES 3

Laszlo Balla
ServiceNow Employee
ServiceNow Employee

You might want to look at leveraging UI Scripts. To call it from a client script, see this page for further reference.

Hello @Laszlo Balla Thanks for your approach. But GlideUiScript has a problem 

                             ---   "To use this API, the UI Type field must be set to Mobile / Service Portal or All on both the client script and the UI script. It cannot be set to Desktop."

Is there any other way?

If you set the UI Script Global (chckbox ticked), you should be able to call it by it's name on the client side e.g. myUIScript() or var xy = new myUIScript() etc.