About service portal widget scripts

__17
Tera Expert

I want to know when the service portal widget script is executed.

Does the server script work when the widget is executed (such as when a button is clicked)?
Or is there an item to set the script execution timing?


Regarding the client script, the code is written in "function ($ scope, spUtil, spUIActionsExecuter, spModal) {}", but I'm not sure if the execution timing is at the time of loading.

I'm thinking of customizing the default "Approve" widget, but I want to understand the default code content before customizing it.

1 ACCEPTED SOLUTION

Tom Sienkiewicz
Mega Sage

The server script part is basically executed on widget load first, if you do not add any IF condition to that code block. This can be used to pre-set widget options from script, populate some scope data variables, run Glide Records before passing data to client etc.

You can call the server script "ad-hoc" from a client script by using spUtil.get(). The unconditional server script wil also be re-called any time you use spUtil.update() or spUtil.refresh().

To add extra code from a click of a button, you would typically add a "ng-click" in the HTML part, connected to a function in the client script, which then uses spUtil.get() to pass scope data to server and specify which server-side function to run. Look up some examples of using spUtil.get() online and you will see the pattern.

 

View solution in original post

2 REPLIES 2

Tom Sienkiewicz
Mega Sage

The server script part is basically executed on widget load first, if you do not add any IF condition to that code block. This can be used to pre-set widget options from script, populate some scope data variables, run Glide Records before passing data to client etc.

You can call the server script "ad-hoc" from a client script by using spUtil.get(). The unconditional server script wil also be re-called any time you use spUtil.update() or spUtil.refresh().

To add extra code from a click of a button, you would typically add a "ng-click" in the HTML part, connected to a function in the client script, which then uses spUtil.get() to pass scope data to server and specify which server-side function to run. Look up some examples of using spUtil.get() online and you will see the pattern.

 

Thank you for answering!
It was easy to understand!