Use of a common JavaScript file in ServiceNow.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-04-2023 08:53 AM
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-04-2023 09:22 AM
You might want to look at leveraging UI Scripts. To call it from a client script, see this page for further reference.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-04-2023 10:19 PM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2023 01:52 AM
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.