Develop > Tailoring > Advanced functions > Scripting > Executing scripts > Executing a script from a stored query

Executing a script from a stored query

A script executed from a stored query searches for records by allowing the user to select precise search parameters. The Service Manager standard system contains an inactive script that can execute from a stored query to display a list of key words relating to previous incidents. The stored query then uses the key word selected to search for similar incidents.

This stored query runs from an open incident record using either Format Control or a displayoption (Screen ID: apm.edit.problem). In this example, a displayoption has been created that adds an option called Probable Cause to the More Actions menu of an open incident record. This option runs the stored query called probcause.user.

The stored query, probcause.user, executes the script called probcause.user.1.

The script probcause.user.1 has a single panel that displays the probcause.user.1 form. The condition for exit (null($key.words)) requires the user to choose a key word before allowing the script to exit.

Important: Scripts executed from stored queries typically set values into the same fields used by the query to retrieve records. In this example, the common field is key.words.

The script is executed before the form from the query (probable.cause.user) opens. The form opened by the script is called probcause.user.1 and supplies the query form with a key word for searching.

When the user selects a key word and clicks OK, the script exits. The stored query then uses the key word to search the probcause file for matching entries. If more than one match is found, the system displays a record list of possible causes for your incident.

Click a selection to view the details with the probable.cause.user form. When you have finished viewing all the choices, click Cancel to return to the incident record.

Related concepts

Scripting
Executing scripts