- 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 12:58 AM
Yes Kalaiarasan, I understand.
Lets assume we have below 6 records
ID | Status | Substate |
1 | X | Y |
2 | X | A |
3 | X | B |
4 | P | Y |
5 | Q | Y |
6 | X | Y |
In that I want to filter out the records Status=X with Substate=Y. That
means output should be only 2,3, 4, 5 records (1 and 6 should be filtered
out).
status!=X is gives the records which are not having the status 'X'. So all
the 1, 2, 3, 6 will be skipped irrespective of substate. Then output is 4,
5.
'^' will add the and condition
state!=Y will skip the remaining 4, 5.
Actually, I am expecting the output as 2, 3, 4, 5. How can we write the
addQuery or addEncodedQuery condition for this?.
On Fri, Jan 9, 2015 at 2:40 AM, Kalaiarasan P <

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2015 01:02 AM
Can you just check if it works or not ? It should work and give you the filtered records as you need...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2015 01:07 AM
Sorry, no luck already I tried that.
On Fri, Jan 9, 2015 at 3:02 AM, Kalaiarasan P <
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2015 02:02 AM
What about this, about long but I think it will work:
gs.addEncodedQuery('state=X^substate!=Y^NQstate!=Y^substate=X^NQsubstate!=X^state!=Y');
So we're basically saying show anything where:
State = X and Substate != Y OR
State != X and Substate = Y OR
State != X and Substate != Y
This means we're only removing the records where state = X and substate = Y, which would return onle rows 2, 3, 4 and 5 in your example.
Let me know if you have any luck with this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2015 02:21 AM
Thank you, very much Adam...:)