Call UI script from an Onload Catalog client script

jglen
Giga Expert

Hi to everyone,

By using the documentation i've tried to call the helloword script example in a Onload Client Script but it's retrun an error : find_real_file.png

Any Idea ?

find_real_file.png

find_real_file.png

Thank you in advance,

1 ACCEPTED SOLUTION

The SN Nerd
Giga Sage
Giga Sage

If you are testing in Service Portal, you need to add the UI Script to your Service Portals Theme.

Navigate to Service Portal > Themes and select the theme being used (Stock is the default).

Then, add the UI Script via the related list JS Includes at the bottom of the form (New)

find_real_file.png

Please note that UI Scripts ran from Service Portal have no access to g_form.


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

View solution in original post

7 REPLIES 7

Mike Patel
Tera Sage

you can create onLoad script like and than call function in onchange as you are doing.

function onLoad() {

}

helloWorld = function(){

alert("hi");

};

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
if (newValue == '') {
}
return;
}

helloWorld();
}

Hi Mike Patel,

 

Thank you for your answer. 

 

If I understand correctly, I have to create an Onload client script named"helloWorld()" Then, create my  OnChange script ?

Is there a way to do it more "global" ? I will need to you this function  in client script a loot of time. It will be usefull to define only one time this function.

 

 

fix type on you onchange first and see if that works.

There us typo on your OnChange script. it should be helloWorld();

Hi, Mike Patel,

 

I've tried by "copy/paste" your script and rename the OnChange Script and I've the same issue.

find_real_file.png