Unable to query with date field

Sush
Tera Contributor

Hi,

 

I need to use below query on one of the table,it is not working as expected

 

encodedquery="location="+location+"startON"+startdate+"@javascript:gs.dateGenerate("+startdate+",'start')@javascript:gs.dateGenerate("+startdate+",'end')";

 

Please suggest what I am missing here

3 REPLIES 3

Brad Bowman
Kilo Patron
Kilo Patron

You are missing separators - and/or - between each condition.  If you can filter a list view similar to what you're expecting, then just copy the query (right-click on the last breadcrumb, copy query) and paste it in the script you're trying to use it in, replacing only the values with "+script_variable+".  So "startON... should be "^startON... if you're trying to query for record(s) with the location, AND start...whatever comes next.  Use ^NQ if this should be an OR condition.  There could be other issues with the remaining part, but copying the query from the list view will show you that also.  If you still can't get it to work, let me know what table this is, and what you're trying to query on - in pseudocode.

Hello @Brad Bowman  ,

 

This is the query that I got after copying query from list view

 

location=bd8bc6911b72d1d024d6724d6e4bcba4^startON2023-03-09@javascript:gs.dateGenerate('2023-03-09','start')@javascript:gs.dateGenerate('2023-03-09','end')

 

As it is static,I replaced the above query with

grRe.addEncodedQuery("location="+location+"^startON"+startdate+"@javascript:gs.dateGenerate("+startdate+",'start')@javascript:gs.dateGenerate("+startdate+",'end')");

 

In location variable I have the sys id and for the startdate I have below config

 

var start='2023-03-09T15:30:00Z';

var startdate=new GlideDateTime(start).getDate();

 

It is not working even now

 

 

 

If you log startdate you'll probably see that it is undefined or not '2023-03-09'.  I assume you're not hard-coding start, as that would still be static.  If this is the value you are getting from a field in the script, or if it's hard-coded, you can use:

var startdate = start.substring(0,10);

so that startdate should have a value of '2023-03-09' but log it to be certain.