---
sourceDocument: Brazil Sales Customer Relationship Management
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/order-management

 Release :

    - brazil

ft:locale :

    - en-US

ft:publication_title :

    - Brazil Sales Customer Relationship Management

ft:clusterId :

    - omgmt

bundleId :

    - omgmt

workflow :

    - Customer and Industry


---

# Minimizing table queries

# Minimizing table queries {#ariaid-title1}

Release version: Brazil  
Updated March 12, 2026  
![](https://www.servicenow.com/docs/portal-asset/ico-clock) 3 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 Minimizing table queries

Minimizing the number of database queries is critical for maximizing performance in ServiceNow configurations.
Excessive queries slow system responsiveness, so efficient query design helps keep performance optimal.
This content explains practical strategies for reducing queries within rules and scripts to improve processing speed.
Show full answer Show less  

## Implementing Rules

When defining determination rules, carefully consider how queries are structured:

* If only a single calculated value (e.g., volume) is needed downstream, consolidate queries into one advanced determination rule that retrieves all necessary fields at once before computing the result.
* If multiple individual fields (e.g., length, width, height) are also needed elsewhere, create separate determination rules for each field with their own queries. This avoids redundant queries when those fields are used independently and prevents running an extra query in a combined calculation rule.
* Be mindful of which fields are associated with a rule. Rules re-run whenever any associated field changes, triggering their queries again. Avoid including unnecessary fields so queries only run when truly needed.
* For calculations dependent on multiple fields (e.g., mass = volume × density), split the calculations across multiple rules---one for volume and one for mass. This way, volume is only queried and calculated once, while mass recalculates as density changes without repeating volume queries.

## Querying a List

When querying tables for multiple values, such as those from a multi-select picklist, prefer a single query using an IN clause rather than multiple queries in a loop. For example, instead of querying the "hues" table once per selected color, query it once for all selected colors together. This reduces the total number of queries and improves efficiency.

## Key Outcomes

* Fewer queries improve system performance and reduce processing overhead.
* Thoughtful rule design prevents redundant data retrieval and excessive recalculation.
* Consolidating multi-value queries into single statements reduces database load.
* Applying these techniques leads to faster, more scalable ServiceNow configurations.  
Learn how to minimize queries to maximize performance.

The more queries you have, the more they impact performance. This article discusses two ways to minimize queries to help keep performance as fast as possible.

## Implementing rules {#table_queries__implementing_rules_to_minimize_queries}

When you create a configuration, consider how you might implement it to minimize queries.

For example, suppose you have a table of the length, width and height of various components. Once you select a part number, you want to query those values to calculate the volume. The best way to query that
information depends on the use case and where the values are needed downstream of the query.

If the configuration only uses the total volume, the best approach is to put the query in the advanced determination rule for the volume, similar to this simplified code:

* Query L,W and H from table
* Var vol = L\*W\*H
* Return vol

{#table_queries__ul_y1j_21q_2hc}

Total queries: 1.

However, if you are writing a volume rule and you know you will need to use the length, width and height values elsewhere, the above code is not appropriate. Instead, you should write your determination rule as
follows:

* Var vol=L\*W\*H
* Return vol

{#table_queries__ul_xrk_h1q_2hc}

You should have the queries in the determination rules. Determination rules can only define one field at a time, so this would need three determination rules---one rule each for length, width and height---and three
queries. Doing this prevents running a fourth query (one in each length, width and height rule, and one in the volume determination rule).

Another way to reduce queries is to be aware of the fields associated with a rule. Suppose you have a query in a rule that references a lot of fields. The rule runs every time one of the fields associated with
that rule changes. Therefore, the query runs every time.

Let's say you need to calculate the volume and then multiply that volume by density (which could change based on material the user selects) to get the total weight. The user does not need to use volume anywhere
else downstream. Here is a sample script:

* Query L,W,H from table
* Var vol= L\*W\*H
* Var mass = vol \* cfg.density
* Return mass

{#table_queries__ul_jd5_41q_2hc}

The problem is that every time the density changes, the rule runs and then the query runs. But the values of L, W and H do not change. Therefore, the processor has to go to the table, find the values for L, W and
H, and redefine the variable `vol` to the same value it was before. A better approach is to calculate volume as a separate field with a separate rule. Then, write the mass rule as follows:

    var mass = cfg.volume * cfg.density;
    return mass;

Mass still recalculates every time, but it is intended to. No processing time is wasted doing unnecessary querying and redefining values.

## Querying a list {#table_queries__query_a_list}

As seen above with L,W and H, you can pull multiple columns from a table in a single query. At other times, you might want to query the table on multiple values. For example, suppose you have a multiselect
picklist (field name `selectedColors`) of different colors. You also have a "hues" table that has a red, blue and green column to tell you the ratios.

If you wanted to query the table for all the selected options of the multiselect picklist, there are two options.

    for (color of cfg.selectedColors){
            var tableResults=lookup("Select blue, red, green from hues where value := value", {"value": color});
            //more code

This `for` loop means that the number of queries is based on the number of selected options for the `selectedColors` field. Alternatively, the following code queries the table
once.

    var tableResults=lookup("select blue, red, green from hues where value in (:list)", {"list": cfg.selectedColors});

This method is better.

For more information on what is supported in a query, see [The lookup function: commands and syntax](https://servicenow-prod.fluidtopics.net/R4NEeH2BHxTgxjiDYzaoRw "Use the lookup function to return information from a user-managed table.").

