---
sourceDocument: Brazil Build or modify applications
sourceDocumentLink: https://www.servicenow.com/docs/r/application-development

 Release :

    - brazil

ft:locale :

    - en-US

ft:publication_title :

    - Brazil Build or modify applications

ft:clusterId :

    - cadev

bundleId :

    - cadev

workflow :

    - Development, Data, and Analytics


---

# Step execution scripts

# Step execution scripts {#ariaid-title1}

Release version: Brazil  
Updated September 10, 2026  
![](https://www.servicenow.com/docs/portal-asset/ico-clock) 2 minutes to read
Summarize  
![AI sparkle icon](https://servicenow.com/docs/portal-asset/ai-sparkle-icon) Summarized using AI  
This content was generated using new OpenAI-powered functionality. Results are provided on an as is basis and are not guaranteed to be accurate or complete.  

## Summary of Step execution scripts

Step execution scripts in ServiceNow define the specific behavior of a step during its execution within a step configuration record.
These scripts interact with input and output variables and control the success or failure of the step, including logging relevant messages.
Show full answer Show less  

## Step Inputs and Outputs

* **Inputs:** Defined in the inputs related list of the step configuration record, accessible in the script via `inputs.variableName`.
* **Outputs:** Defined in the outputs related list and accessible via `outputs.variableName` to pass data from the step script.

## Controlling Step Result

The `stepResult` parameter provides an API to manage the step's outcome:

* `stepResult.setSuccess()` marks the step as successful.
* `stepResult.setFailed()` marks the step as failed.
* `stepResult.setOutputMessage(message)` sets the step log message; multiple calls overwrite previous messages.

## Example Use Cases

* **Record Query Step:** A script that queries a table based on input filters and sets outputs accordingly. It fails if inputs are missing or no matching records are found, otherwise it succeeds and logs the record count.
* **Custom Scripted Step with Timeout:** A script that waits (polls every second) for an asynchronous process to finish within a timeout period. It passes the step if the process completes successfully before the timeout, or fails if the timeout is reached.

## Practical Application for ServiceNow Customers

By configuring step execution scripts, customers can customize automated workflows to perform complex logic, validate inputs, query records, and handle asynchronous operations with precise control over success criteria and logging. This enables more robust and transparent automation aligned with business requirements.

For server-side script execution, similar logic applies but success/failure is indicated by returning `true` or `false` instead of using `stepResult` methods.  
In a step configuration record, the step execution script field determines what a step
with this configuration does when it runs.

## Step inputs

The input variables to a step are determined by the inputs related list in the step
configuration record. The inputs parameter to
`executeScript()` gives the script access to these variables. For example, if
the inputs related list contains two records, <var class="keyword varname">var1</var> and
<var class="keyword varname">var2</var>, the script can reference <var class="keyword varname">var1</var> with the expression
`inputs.var1` and can reference <var class="keyword varname">var2</var> with
`inputs.var2`.

## Step outputs

The output variables to a step are determined by the outputs related list in the step
configuration record. The outputs parameter to
`executeScript()` gives the script access to these variables. For example, if
the outputs related list contains two records, <var class="keyword varname">out1</var> and
<var class="keyword varname">out2</var>, the script can reference <var class="keyword varname">out1</var> with the expression
`outputs.out1` and can reference <var class="keyword varname">out2</var> with
`outputs.out2`.

## Step result

The stepResult parameter provides access to an API that controls whether
the step passes or fails. It also determines the message the step writes to the log.

The method `stepResult.setSuccess()` causes the step to succeed. The method
`stepResult.setFailed()` causes the step to fail.

The method `stepResult.setOutputMessage()` sets the message to write to the log
when the step succeeds or fails. It takes one parameter: the string to write to the log. If the
script calls `stepResult.setOutputMessage()` more than once, the most recent
value set overwrites any previous value.  

## Record Query step execution script


        (function executeStep(inputs, outputs, stepResult) {
             if (gs.nil(inputs.table)) {
                stepResult.setOutputMessage(gs.getMessage("The '{0}' input variable was not specified",
                   'table'));
             stepResult.setFailed();
              return;
        }
        var query = new GlideRecord(inputs.table);
        query.addEncodedQuery(inputs.field_values);
        query.query();
        if (!query.next()) {
             stepResult.setOutputMessage(gs.getMessage("No records matching query:\n{0}",
                 inputs.field_values));
              stepResult.setFailed();
        } else {
             stepResult.setSuccess();
             outputs.table = inputs.table;
             outputs.first_record = query.getUniqueValue();
             stepResult.setOutputMessage(gs.getMessage("Found {0} {1} records matching query:\n{2}",
                                                      [query.getRowCount(),
                                                       inputs.table,
                                                       inputs.field_values]));
        }
        }(inputs, outputs, stepResult));
        
       
## Custom scripted step configs {#atf-config-script__example_rnc_ldn_qpb}


        ((function executeStep(inputs, outputs, stepResult, timeout) {
    	// Waits up to the timeout for some asynchronous logic to finish
    	// This script checks for completion once a second for up to 60 seconds
    	var counter = 1;
    	// Try for up to 60 seconds
    	while (counter <= timeout) {
    		// If the asynchronous logic is finished, return "true" to pass the step
    		// isMyAsyncLogicFinished() can be replaced with any asynchronous event that needs to be tested
    		if (isMyAsyncLogicFinished()) {
    			stepResult.setOutputMessage("Success!");
    			stepResult.setSuccess();
    			return;
    		}
    		// Wait one second, and log the total number of seconds waited
    		gs.info("Waited " + counter + " seconds for asynchronous logic to finish");
    		sn_atf.AutomatedTestingFramework.waitOneSecond();
    		counter++;
    	}
    	// If this point is reached, the retry loop ran out of tries; return false to fail the step
    	stepResult.setOutputMessage("FAILURE: Timed out after waiting for " + timeout + " seconds");
    	stepResult.setFailed();
    }(inputs, outputs, stepResult, timeout));
        
       
Note:  
The above example can also be used for Run Server Side script by replacing `stepResult.setSuccess()`" and `stepResult.setFailed()` with `return true` and `return false`.

