- 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
‎04-11-2019 03:05 PM
You can check client check box and define onclick function for your ui action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2019 03:09 PM
Take a look at this
https://www.servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/
Please mark my response as correct and helpful if it helped solved your question.
-Thanks

- 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
‎11-26-2019 12:21 AM
Hi,
I am trying to automate and run the UI Action "Refresh Impacted Services" [action name ="refresh_impacted_services"] in the Change form on Save (Load).
I have tried your code but its not working.
Firstly I'm not a developer (so its find it on google and give it a go....)
so the bit "Code here" in your script, am I supposed to write some code to make this work?
function onLoad() {
}
function refresh_impacted_services() {
// Code here << do I need anything here??
}
If no code required, then any idea why its not working?
Thanks
Nigel