
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2022 12:53 PM
Hey fellas!
I'm trying to figure out how to run a query against multiple status as well as run a query against todays date.
Basically, we have a due date field that, if that due date is within 2 days from today. We need to check a rush box field we have. So, if the ticket is due April 4th, then I need our Rush Box to be force checked if today is April 2nd. I'm building out a Scheduled Job for this but having trouble with the syntax.
//Queries customer ticketing for anything due within 2 days from today
var date = new GlideDateTime();
var rush = new GlideRecord('u_custom_ticketing');
rush.addQuery('active', true);
rush.addQuery('status', '!=', '5'|'4');
rush.addQuery('u_due_dates');
The above is what I've typed up so far. I doubt the pipe is the way to approach the multiple statuses, and I'm not really sure how to tackle basically; IF Due Date IS LESS THAN 2 Days From Today
Thank you in advance for the assistance!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2022 02:00 PM
Hi Leo,
Do you want to know a secret? 🙂
If you are able to filter that data in the list view, then this is piece of cake!!
Check this example here: I will filter in the incident table, active records with status New and In Progress:
Then, on top, I will see the filter query:
Now, if I right click on the end of the filter query (in my case the "state in (New, In Progress)"), I will see three options:
From there, you select "Copy query".
Then, go to your script and use the addEncodedQuery method:
//Queries customer ticketing for anything due within 2 days from today
var date = new GlideDateTime();
var rush = new GlideRecord('u_custom_ticketing');
rush.addEncodedQuery("<paste here your query>");
rush.query();
while(rush.next()){
//do something!!
}
My query look like: active=true^stateIN1,2
Hope this helps you in your quest!!
Please, if this answer is relevant for you, please mark it as correct and helpful.
Thanks,
Filipe

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2022 02:00 PM
Hi Leo,
Do you want to know a secret? 🙂
If you are able to filter that data in the list view, then this is piece of cake!!
Check this example here: I will filter in the incident table, active records with status New and In Progress:
Then, on top, I will see the filter query:
Now, if I right click on the end of the filter query (in my case the "state in (New, In Progress)"), I will see three options:
From there, you select "Copy query".
Then, go to your script and use the addEncodedQuery method:
//Queries customer ticketing for anything due within 2 days from today
var date = new GlideDateTime();
var rush = new GlideRecord('u_custom_ticketing');
rush.addEncodedQuery("<paste here your query>");
rush.query();
while(rush.next()){
//do something!!
}
My query look like: active=true^stateIN1,2
Hope this helps you in your quest!!
Please, if this answer is relevant for you, please mark it as correct and helpful.
Thanks,
Filipe

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2022 02:03 PM
Filipe, you're a life saver. I COMPLETELY forgot about addEncodedQuery.
Thank you so much! I facepalmed as soon as I read that line.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2022 02:09 PM
ahaha! no worries! I did such a detailed explanation since I was not sure that you were aware of it!
But glad that my post helped you! Might help others in the future as well! 🙂
Cheers!
Filipe

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2022 02:49 PM
Hate to ask another question, but having some difficulties getting a proper query out of the preselects from the filters.
'u_due_datesBETWEENjavascript:gs.beginningOfYesterday()@javascript:gs.endOfToday()'
'u_due_dates<=javascript:gs.endOfTomorrow()'
Was toying around with either of these filters. Though there isn't really a 2 day option. Today, Yesterday or Tomorrow is the most it allows.
I was looking at some options about gs.daysAgo option, would that work here in this scenario?
'u_due_dates<=javascript:gs.daysAgo(2)'