Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Need help to AddQuery against todays date and multiple statuses?

Leo Ruggiero
Tera Contributor

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!

1 ACCEPTED SOLUTION

Filipe Cruz
Kilo Sage

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:
find_real_file.png

Then, on top, I will see the filter query:

find_real_file.png

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:
find_real_file.png

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

View solution in original post

4 REPLIES 4

Filipe Cruz
Kilo Sage

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:
find_real_file.png

Then, on top, I will see the filter query:

find_real_file.png

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:
find_real_file.png

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

Filipe, you're a life saver. I COMPLETELY forgot about addEncodedQuery.

Thank you so much! I facepalmed as soon as I read that line. 

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

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)'