- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2019 03:03 PM
Hi
How do we call Client script from UI Action. Please help me in understanding this.
Thanks,
Saurabh
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2019 05:38 PM
Options below, with limitations
1) Place a function in an onload script (only works in global scope)
Client Script
function onLoad() {
}
// You can call this in UI Actions
// Only works in global scope (does not work in scoped apps)
// Will only work for UI Action of the same table
function yourFunctionHere() {
// Code here
}
UI Action
yourFunctionHere();
2) Write a UI Script
UI Script yourFunctionHere
// This will be callable from all client scripts form any table
// If global is not ticked, you must use ScriptLoader API
function yourFunctionHere() {
// Code here
}
UI Action
//If global is not ticked on UI Script
getScripts("yourFunctionHere", runScripts)
function runScripts() {
yourFunctionHere();
}
//If global is ticked on UI Script
yourFunctionHere();
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2020 05:28 PM
With the introduction on scoping, i don't think the solution above works anymore.
My recommendation would be to use UI scripts for all re-usable client script code.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2020 01:32 PM
1) The client script should be in global scope, Isolate Script should be false and UI Action should be on the same table as Client Script