Encoded Query & Add Or Condition query

inderpal
Kilo Expert

Hi All,

I am stuck on a scenario where I need to query records from a table with the combination of one encoded query saved in a field or on the basis my static query.

For ex: I need to fetch incident tickets where active is true or my encoded query matches.

I tried following query but it seems addEncodedQuery method doesn't work with addOrCondition method.

current.addEncodedQuery("short_description=Test").addOrCondition("active","true");

 

Does anyone know how to make both Encoded query & addOrCondition working together? Please HELP!!

 

Thanks in advance,

Inderpal Singh

ipsindhuria1992@live.com

 

8 REPLIES 8

Mike Patel
Tera Sage

You need something like below

current.addEncodedQuery('active=true^NQshort_description=test');

 

NQ is basically below

find_real_file.png

inderpal
Kilo Expert

Hi Mike,

 

Thanks for replying.

The problem is not this much simple. Sorry I didn't explain the scenario in detail.

I want to use these queries in Before Query Business rule on Incident table. Problem in using "^NQ" in encoded query of before query business rule is that when system queries record from table, it always forces the records matching the query coming after ^NQ irrespective of the filter I have applied on the List filter.

See below screenshot for the reference.

Issue here is if I am applying any filter on the list, my before query business rule always pushing the data matches query after ^NQ on the list.

 

Below is my encoded query which I have used in before query business rule.

current.addEncodedQuery('active=true^NQcaller_idSTARTSWITHLHR User')

 

Because of this below filter is not working properly.

find_real_file.png

I think the breadcrumb (filter) will still be the same but it will force the result based upon the before query business rule. I tried below and it gives the result as expected but breadcrumb is till same.

current.addEncodedQuery('short_description=Testing^active=true');

find_real_file.png

The SN Nerd
Giga Sage
Giga Sage

Perhaps this post will be helpful

How To Write GlideRecord Queries Like A Pro - Encoded Queries

find_real_file.png


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022