- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2022 11:36 PM
I'm trying to write an Encoded Query.
The situation that start date and end date are earlier than date A
and the situation that start date and end date are after date B
I would like to write a encoded query that can obtain results except for the above two cases.
ex)
gr.addEncodedQuery( !('start_date<A ^ end_date<A'));
gr.addEncodedQuery( !('start_date>B ^ end_date>B'));
The above query is a query that I wrote as an example. I don't know how to write it.
Does anyone know how to write the right query?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2022 12:48 AM
My bad. Re-read the question,
The total situation is (start_date, end_date <= b) or (start_date, end_date >= A).
Would need to query twice and combine the results.
That is
var resultArray = [];
var gr1 = new GlideRecord('<table name>');
gr1.addQuery('start_date', '<=', B);
gr1.addQuery('end_date', '<=', B);
gr1.query();
while(gr1.next()) {
resultArray.push(grs1.sys_id.toString());
}
var gr2 = new GlideRecord('<table name>');
gr2.addQuery('start_date', '>=', A);
gr2.addQuery('end_date', '>=', A);
gr2.query();
while(gr1.next()) {
resultArray.push(grs2.sys_id.toString());
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2022 11:44 PM
Hi,
The easiest way to write encoded queries is to set up a filter condition on a list and copy the query.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2022 11:50 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2022 11:58 PM
That is, instead of trying to do below,
! ('start_date<A ^ end_date<A')
try
'start_date>=A ^ORend_date>=A'

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2022 12:48 AM
My bad. Re-read the question,
The total situation is (start_date, end_date <= b) or (start_date, end_date >= A).
Would need to query twice and combine the results.
That is
var resultArray = [];
var gr1 = new GlideRecord('<table name>');
gr1.addQuery('start_date', '<=', B);
gr1.addQuery('end_date', '<=', B);
gr1.query();
while(gr1.next()) {
resultArray.push(grs1.sys_id.toString());
}
var gr2 = new GlideRecord('<table name>');
gr2.addQuery('start_date', '>=', A);
gr2.addQuery('end_date', '>=', A);
gr2.query();
while(gr1.next()) {
resultArray.push(grs2.sys_id.toString());
}