Can I call UI scripts from the portal?

bonsai
Mega Sage

I'm trying to call a UI script by clicking a button I've implemented in the portal.
However, even though I've implemented a script that works on the platform, it doesn't work from the portal...

Is it possible to use UI scripts on the portal?
I'd like to know how.

1 ACCEPTED SOLUTION

Hello @bonsai 

After following the steps in my previous reply, you can directly call the UI Script function from the client controller.

For example, if your UI Script contains:

function showAlert() {
	alert("test");
}

Once you add this UI script as a dependency in the widget’s related list, you can simply call the function in the client controller:

For example:

api.controller = function($scope) {
  /* widget controller */
  var c = this;
  showAlert();
};

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"

 

Thank You

Juhi Poddar

View solution in original post

8 REPLIES 8

WillK2022
Tera Expert

Hi Bonsai,

Please provide the script you are referring to. That way the community can assess whether the script is appropriate for the portal.

Some things to keep in mind:
Not everything that is available to a script on the platform (server-side), will be available to a script on the Portal (client-side). An example of this is the GlideSystem.
For a script on the portal to have access to the "server side" features, you will need to call a server side script by means of a GlideAjax call.
Please refer to the Product Documentation and ask here if you have any more questions:
https://www.servicenow.com/docs/csh?topicname=c_GlideAjaxAPI.html&version=latest

Regards,
Will.

This is the widget configuration.
The UI script is called in the client controller.

bonsai_0-1756101128538.png

 

This is the UI script

 

 

bonsai_1-1756101144600.png

 

You will need to add the UI Script as a dependency.
Please refer to the following Product Documentation:
https://www.servicenow.com/docs/csh?topicname=widget-dependencies.html&version=latest

P.S.
To provide more clarity, you create the dependency in the related lists when viewing your widget page (test_button).
Once the dependency is created, you can go to the platform, navigate to "Service Portal > Dependencies" and open your dependency.
In the JS Includes related list, add a new record, and link it to your UI Script. You'll see that the "Source" supports UI Script.

I hope that helps!