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.

Calling UI script from Client Script is not working

DoDo labs___
Mega Sage
Hi!
 
This is the onChange client script:
 
function onChange(control, oldValue, newValue, isLoading, isTemplate) {


var a = new FIG_get_message();
a.show_message();

    if (isLoading || newValue === '') {
      return;
   }


alert('TEST 1);
 
UI Script:
 
var FIG_alert_message = Class.create;
FIG_alert_message.prototype = {
initialize: function()
{},

show_message: function()
{
    alert('TEST 2');
},
 
But I Get this error: onChange script error: ReferenceError: FIG_get_message is not defined function () { [native code] }
 
How can I call the UI script from onChange Client Script?
1 ACCEPTED SOLUTION

J Siva
Kilo Patron
Kilo Patron

Hi @DoDo labs___ 

Your scripts need few modifications.

PFB.

 

1.UI script:

 

Screenshot_20250315-230041.png

var FIG_alert_message = Class.create();
FIG_alert_message.prototype = {
    initialize: function() {},

    show_message: function() {
        alert('TEST 2');
    },
};

 

2. Client script.

Screenshot_20250315-230708.png

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

   //Type appropriate comment here, and begin script below
   var a = new FIG_alert_message();
   a.show_message();

   alert ('Inside client script ');
   
}

 

Note:

-> Check the UI script name in the client script. It's s not matching with your actual UI script name.

Hope this helps.

Regards,

Siva

View solution in original post

4 REPLIES 4

Vishal Jaswal
Giga Sage
Giga Sage

Hello @DoDo labs___ 

Make one change in your client script: 

 

var a = new FIG_alert_message();

 


Make two changes in your UI script:

1. Add semi colon at the end

var FIG_alert_message = Class.create();
FIG_alert_message.prototype = {
   initialize: function() {},
   
   show_message: function() {
       alert('TEST 2');
   }
};

 

 

2. UI Type: Desktop and check Global 

Here are the results:

Client Script:

vishal_jaswal_0-1742059679080.png

UI Script:

vishal_jaswal_2-1742059919655.png

vishal_jaswal_3-1742059929893.png


Hope it helps!

 




Hope that helps!

The error message is still there 😞

 

DoDolabs____0-1742062959505.png

 

Hello @DoDo labs___ 

Can you provide screenshots of your Client Script and UI Script, the way I posted above.


Hope that helps!

J Siva
Kilo Patron
Kilo Patron

Hi @DoDo labs___ 

Your scripts need few modifications.

PFB.

 

1.UI script:

 

Screenshot_20250315-230041.png

var FIG_alert_message = Class.create();
FIG_alert_message.prototype = {
    initialize: function() {},

    show_message: function() {
        alert('TEST 2');
    },
};

 

2. Client script.

Screenshot_20250315-230708.png

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

   //Type appropriate comment here, and begin script below
   var a = new FIG_alert_message();
   a.show_message();

   alert ('Inside client script ');
   
}

 

Note:

-> Check the UI script name in the client script. It's s not matching with your actual UI script name.

Hope this helps.

Regards,

Siva