- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2015 12:12 AM
Hi All,
I am looking for addQuery/addEncodedQuery..etc to write below scenario to filter out the two column values at a time.
I have a two choice fields 'State' and 'Substate' with some choice values. I want to get the records which are not in State=X with Substate=Y.
var gr = new GlideRecord('table_name');
gr.query();
while(gr.next())
{
if(!(gr.status==X && gr_sasset.substate=='Y'))
{
//Some logic goes here
}
}
Instead of writing a if condition in the while loop, is there any alternate way to filter the records using addQuery/addEncodedQuery...etc. and for the same scenario how can we set filters for list in the UI (instead of script)?. Please suggest me in this, thanks in advance.
Thanks & Regards,
Raju.
Solved! Go to Solution.
- Labels:
-
Integrations
-
User Interface (UI)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2015 02:03 AM
I have created table as per your requirement in demo please click below link to login
https://demo013.service-now.com/login.do
username and pwd : admin
After login click this below link

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2015 01:20 AM
Hi Raju,
Wite query as per below it should give result as expected
status=x or substat=y
AND
status!=x andsubstatus!=y
Regards,
Harish.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2015 01:35 AM
Sorry Harish, No luck.
On Fri, Jan 9, 2015 at 3:20 AM, Harish Murikinati <
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2015 01:20 AM
Easiest way
Do you're filtering on a list manually.
Right click "Copy Query"
use addEncodedQuery('my_very_long_query') in your script.
This is because the "OR" (^NQ) doesn't have any query function so encoded querie instead will do the job.
ps: Don't forget to very well comments the code and maybe have a story/incident/change number somewhere (useful if you want to remember in 1 or 2 years why you have this complex query) explaining the business requirements and who did approve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2015 01:34 AM
Hi David,
To get that result as I expected, I am unable to set the filters in list
view manually.
Regards,
Raju.
On Fri, Jan 9, 2015 at 3:20 AM, David Legrand <

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2015 01:37 AM
Are you able to write this query. This can work as expected.
(status == X OR Substatus == Y) AND (status != X AND Substatus != Y)