On occasion, I need a general UI Action on a List in ServiceNow that is not specific to any one record in the list. For example, I might have a table that lists all of the Fruit inventory of a store. Let’s say that every night, we have have a job that runs and calculates any fruit that may have reached it’s expiration date so that it can dispose of them or signal them for markdown.

Sometimes, however, an administrator might be viewing the fruit and realize that we need to do that calculation right away rather than wait until the next scheduled evaluation period.

The administration might want a List Button or a List Link that they can push to tell the backend system to process the scheduled job to evaluate all of the fruit.

At first glance, you may do what I always do, and try to write a quick Server-side UI Action to trigger that event. However, when you click the button, you get the following error:

Error: No Records Selected

Error: No Records Selected

Since this is a list action, the system wants you to select records in the list before trying to click the server-side operation, even though your UI Action has nothing to do with a specific record on the list.

One way around this is to create a client-based UI Action. The error will not come up on the client portion of the UI Action’s function. However, if you want your client script to trigger a server-side operation that pesky error will pop up again. You could have your client script redirect the user to some processor, portal page, etc that triggers the job to execute, but that is a lot of overhead and has some potential security concerns if you don’t build it properly.

The quickest way to solve this problem is to create a client/server combination UI Action where the “Action” field has a name that starts with “sysverb_”.

Here is a sample UI Action:

Name: Recalculate expiration status
Action name: sysverb_recalculate_expirations
Client: true
List link: true
Onclick: processExpirations()
Script:

1
2
3
4
5
6
7
8
9
10
11
function processExpirations() {
    g_list.action('d8c74edadb5e4810262673e1ba961939', 'sysverb_recalculate_expirations');  
}

if (typeof window == 'undefined') {
    processServerSide();
}

function processServerSide() {
    //execute code to calculate fruit expirations
}

Now, I can click the link on the list without selecting any records and it will kick off my process for my fruit.