Skip to page contentSkip to chat
ServiceNow support
    • Community
      Ask questions, give advice, and connect with fellow ServiceNow professionals.
      Developer
      Build, test, and deploy applications
      Documentation
      Find detailed information about ServiceNow products, apps, features, and releases.
      Impact
      Accelerate ROI and amplify your expertise.
      Learning
      Build skills with instructor-led and online training.
      Partner
      Grow your business with promotions, news, and marketing tools
      ServiceNow
      Learn about ServiceNow products & solutions.
      Store
      Download certified apps and integrations that complement ServiceNow.
      Support
      Manage your instances, access self-help, and get technical support.
Using operator (^NQ) in encoded queries causes incorrect reference links in the list view - Known Error
  • >
  • Knowledge Base
  • >
  • Known Error (Knowledge Base)
  • >
  • Using operator (^NQ) in encoded queries causes incorrect reference links in the list view
KB0564887

Using operator (^NQ) in encoded queries causes incorrect reference links in the list view


30846 Views Last updated : Mar 18, 2024 public Copy Permalink English (Original)
  • English (Original)
  • Japanese
KB Summary by Now Assist

Description

When using the operator ^NQ in an encoded query within a business rule, the results appear in the list view, but the reference links are not correct.
A filter on a business rule that has a query with the operator ^NQ (second level condition) is applied only on the first part of the query. Although the business rule works correctly in the list, if a filter like Active=true is added, the filter is applied only on the first part of the query (before the ^NQ).

Steps to Reproduce

  1. Create a business rule:
    • Name: Test condition
    • Table: Incident [incident]
    • When: Select before from the drop-down list
    • Query: [Select the check box]
    • Advanced: [Select the check box]
    • Condition: gs.getSession().isInteractive()
    • Script:
      function onBefore(current, previous) {
              current.addEncodedQuery('active=false^NQactive=true');
          }
  2. Load the Incident list view.
    Note the inconsistencies. If you click an incident number, the form for a different incident opens.

 

Workaround

This is expected behavior. To understand why this issue occurs, the following details about how the NQ operator works and why it is not appropriate for a business rule are provided.

The NQ (top level OR) operator will OR all previous query terms with following query terms. When there are no previous query terms, it is equivalent to regular OR. 

For example, if the query expression is:
      active=true^NQactive=false 

the query is:
      (active = true OR active = false)


However, if there is a query expression already, for example (number=INC000004), then appending the query expression active=true^NQactive=false makes it:

    number=INC000004^active=true^NQactive=false 

this is equivalent to the query:
    (number=INC000004 AND active = true) OR (active = false)

it is not the expected query:
    (number=INC000004) AND (active = true OR active = false)

When the query is evaluated, if the record INC000004 has active=false, the OR part takes place so the record returned is the first record with active=false. Because the database orders records in an arbitrary manner, this can be any record with active=false and, specifically, it need not be INC000004. 

This is why using NQ operators in a context where it is appended to an existing query yields unexpected results. This includes business rules, etc. When it is used in contexts where the entire query expression is known, the equivalent query is clear. When NQ is appended to an existing query, the equivalent query expression may alter the meaning of the original query itself.

Specifically for a before query business rule, the intent of adding additional query terms is that the result is a subset of the original query. Adding NQ changes the meaning of the entire query. Also note that adding a before query business rule changes the query not just in specific use cases (like list view), but in all use cases where a query is performed (form view).


Related Problem: PRB647484

The world works with ServiceNow.

Sign in for more! There's more content available only to authenticated users Sign in for more!
Did this KB article help you?
Did this KB article help you?

How would you rate your Now Support digital experience?

*

Very unsatisfied

Unsatisfied

Neutral

Satisfied

Very satisfied

Very unsatisfied

Unsatisfied

Neutral

Satisfied

Very satisfied

What can we improve? Please select all that apply.

What are we doing well? Please select all that apply.

Tell us more

*

Do you expect a response from this feedback?

  • Terms and conditions
  • Privacy statement
  • GDPR
  • Cookie policy
  • © 2025 ServiceNow. All rights reserved.