---
sourceDocument: Brazil Build workflows
sourceDocumentLink: https://www.servicenow.com/docs/r/build-workflows

 Release :

    - brazil

ft:locale :

    - en-US

ft:publication_title :

    - Brazil Build workflows

ft:clusterId :

    - crworkflow

bundleId :

    - crworkflow

workflow :

    - Creator


---

# Global variables

# Global variables in business rules {#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 Global variables in business rules

In ServiceNow business rules, predefined global variables enable scripting access to the system state and context during record operations.
These variables help you reference the current and previous states of records, execute GlideSystem functions, and communicate data between server and client scripts.
Show full answer Show less  

## Key Features

* **current**: Represents the current state of the record being processed. It is essential to check for null values to avoid errors.
* **previous**: Holds the state of the record before any updates within the execution context. It is only available during update and delete operations and not in asynchronous scripts.
* **gscratchpad**: A scratchpad object used in display business rules to pass information from server-side scripts to client scripts.
* **gs**: Provides access to GlideSystem functions for system-level operations.

These variables are globally accessible across all business rules within the same transaction, enabling consistent reference to the record's state.

## Best Practices for Safe Use

* **Preventing null pointer exceptions:** Before using `current` or `previous`, verify they are not null to avoid runtime errors, e.g., `if (current == null) return;`.
* **Variable scope management:** User-defined variables declared directly in business rules are global by default and accessible across subsequent business rules, potentially causing conflicts and unexpected behavior.
* **Encapsulate code in functions:** Wrapping your business rule script inside a function confines variable scope locally, preventing collisions with other scripts. For example, declare variables like `nowGR` inside a function rather than globally.
* **Ensure availability of variables within functions:** Variables such as `current` must be accessible at the time the function is invoked.

## Practical Impact

Understanding and properly using global variables in business rules allows you to accurately track and manipulate record states during transactions, pass data to client scripts, and leverage system functions. Following scope and null-check best practices ensures reliable and maintainable scripting, reducing risks of errors and unintended side effects across multiple business rules running in the same transaction.  
Predefined global variables are available for use in business rules.
Use the following predefined global variables to reference the system in a business rule
script.  
{#c_UsingPredefinedGlobalVariables__table_jsc_wcw_lz__entry__2}

| Global variable | Description |
|-|-|
| <var class="keyword varname">current</var> | Current state of the record being referenced. See "Prevent null pointer exceptions" below to check for nulls before using this variable. |
| <var class="keyword varname">previous</var> | State of the referenced record prior to any updates made during the execution context, where the execution context begins with the first update or delete operation and ends after the script and any referenced business rules are executed. If multiple updates are made to the record within one execution context, <var class="keyword varname">previous</var> will continue to hold the state of the record before the first update or delete operation. Available on update and delete operations only. Not available on async operations. See "Prevent null pointer exceptions" below to check for nulls before using this variable. |
| <var class="keyword varname">g_scratchpad</var> | Scratchpad object is available on display business rules, and is used to pass information to the client to be accessed from client scripts. |
| <var class="keyword varname">gs</var> | References to [GlideSystem](https://www.servicenow.com/docs/access?context=c_GlideSystemScopedAPI&version=brazil&pubname=brazil-api-reference&ft:locale=en-US) functions. |
[ ]

{#c_UsingPredefinedGlobalVariables__table_jsc_wcw_lz}

The variables <var class="keyword varname">current</var>, <var class="keyword varname">previous</var>, and
<var class="keyword varname">g_scratchpad</var> are global across all business rules that run for a
transaction.

## Prevent null pointer exceptions {#c_UsingPredefinedGlobalVariables__null}

In some cases, there may not be a <var class="keyword varname">current</var> or <var class="keyword varname">previous</var> state for the record when a business rule runs, which means that the variables will be null. To check for null before using a variable, add the following code to your business rule:

    if (current == null) // to prevent null pointer exceptions.
    return; 

## Define variables {#c_UsingPredefinedGlobalVariables__section_c1q_xdw_lz}

User-defined variables are globally scoped by default. If a new variable is declared in an
order 100 business rule, the business rule that runs next at order 200 also has access to
the variable. This may introduce unexpected behavior.

To prevent such unexpected behavior, always wrap your code in a function. This protects
your variables from conflicting with system variables or global variables in other business
rules that are not wrapped in a function. Additionally, variables such as
<var class="keyword varname">current</var> must be available when a function is invoked in order to be
used.  
The following script is vulnerable to conflicts with other code. If the variable <var class="keyword varname">now_GR</var> is used in other rules, the value of the variable may unexpectedly change.

    var now_GR = new GlideRecord('incident');
    now_GR.query(); 
    while(now_GR.next()) {
     
       //do something
     
    }

When this script is wrapped in a function, the variable is available only within the function and does not conflict with other functions using a variable named <var class="keyword varname">now_GR</var>.

    myFunction();
     
    function myFunction() { 
      var now_GR = new GlideRecord('incident');
      now_GR.query(); 
      while(now_GR.next()) { 
        //do something 
    } }


