Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How do we call Client script from UI Action

saurabhsharma
Giga Contributor

Hi 

How do we call Client script from UI Action. Please help me in understanding this.

Thanks,

Saurabh

1 ACCEPTED SOLUTION

The SN Nerd
Giga Sage
Giga Sage

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

View solution in original post

6 REPLIES 6

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

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