Use the Script Action utility in a Virtual Agent topic to run a script.

Script Action utility properties

Property Description
Node name The name that identifies this Script Action node in the topic flow.
Action expression The script that performs an action.
Advanced
Hide this node
Conditionally show this node if

No-code condition statement or low-code script that specifies a condition for presenting this node in the conversation. The condition must evaluate to true.

Example Script Action utility

Figure 1. Script Action utility basic properties
Basic properties include the node name and the action expression that contains the script.

Example script action

(function execute() {
    var list = [];
    if (vaInputs.case_number != "") {
        var gr = new GlideRecord("sn_customerservice_case");
        gr.addQuery("number", "CONTAINS", vaInputs.case_number);
        gr.addQuery("active", "true");
        gr.orderBy("number");
        gr.query();
        while (gr.hasNext()) {
            gr.next();
            list.push(gr.getUniqueValue().toString());
        }
    }
    vaVars.case_list = list;
})()

This example performs a search on the [sn_customerservice_case] table for a specific case number based on the input from another control called case_number. The script then places the results in an array and stores them in the case_list variable, which is accessible by other nodes in the same topic. Because vaVars only supports string, number, and Boolean values, the script uses toString() to store these values as strings. The code is contained in an if statement, so it only executes if the case_number variable has a value. This if statement prevents the code from running if the user has not entered a number.

For more information about writing scripts for Virtual Agent, see Virtual Agent scripts.