Client-side UI actions

To change a UI action to run client-side script, we first need to check the client field tick box. This brings up some additional fields, including the checkboxes to select which list versions the UI actions will be compatible with, but the main new field we are interested in is called onClick

The onClick field runs the client code contained inside it when the UI action is selected. Visually, this is only a small field, and not that appropriate for code, so most developers call a function in this field and define the function in the main script field.

Let's look at an example of this usage. For the code in the onClick field, we only need to call the following function:

onClick();

Then, in the script field, we can define the function and contain the code we want to run inside it:

function onClick() {
// Write script here to run when an UI Action is selected

}

This method of calling a function that resides in the script field is used by ServiceNow UI actions that are provided with the out-of-the-box platform.

We can see what these UI actions would look like in Figure 4.1:

Figure 4.1: Example UI action containing client-side script

In our example in Figure 4.1, we can see the UI action as a form button, as that is the checkbox that has been selected. The call in the Onclick field to the onClick function allows us to write as much code as we need in the script field inside our onClick function.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.247.196