Querying Incident table for date range

monicanegi
Kilo Contributor

Hi ,

I am trying to fetch closed records from Incident table using below request-

I have two closed records with closed_at date as

2017-04-12 19:13:11

2017-05-25 09:29:01

1.Trying to fetch records with closed_at date > '2017-04-12 19:13:10', so i was expecting that it should fetch '2017-04-12 19:13:11'record as well, but it didn't fetch that record.

I had tried with '2017-04-12 19:00:00' as well but it didn't work either.

https://dev34617.service-now.com/api/now/table/incident?sysparm_query=closed_at%3Ejavascript%3Ags.da...

Although >'2017-04-12 00:00:00' does fetch '2017-04-12 19:13:11'.

2. Also trying with >= '2017-04-12 19:13:11', didn't work.

https://dev34617.service-now.com/api/now/table/incident?sysparm_query=closed_at%3E=javascript%3Ags.d...

3.Whereas fetching records < '2017-04-12 19:13:12' , fetches '2017-04-12 19:13:11' record .

https://dev34617.service-now.com/api/now/table/incident?sysparm_query=closed_at%3Cjavascript%3Ags.da...

Also with <='2017-04-12 19:13:11', it fetches the '2017-04-12 19:13:11' record

https://dev34617.service-now.com/api/now/table/incident?sysparm_query=closed_at%3C=javascript%3Ags.d...

4.While trying to fetch data within a date range (startdate as '2017-04-12 19:13:11' and enddate as '2017-05-25 09:29:01'), it fetches '2017-05-25 09:29:01' record but not '2017-04-12 19:13:11'

https://dev34617.service-now.com/api/now/table/incident?sysparm_query=closed_atBETWEENjavascript%3Ag...

So it seems that > and >= are not working as expected. Please help me in resolving this issue and let me know how to use > and >= in my request.

Thanks,

Monica

10 REPLIES 10

Midhun1
Giga Guru

Hi Negi,



What ever filter you wants you can apply in list layout and copy the query   and use that in script like addEncodedQuery     and run the script.


Hi Midhun ,


Thanks for your reply.


But it didn't work.I tried filtering on table, but it doesn't fetch the desired output .


i had tried with closed 'at or after' '2017-04-12 19:00:00' but it didn't fetch record closed at '2017-04-12 19:13:11'.


It seems at or after is not working as expected.Whereas 'at or before' works perfectly fine.



Thanks,


Monica


BALAJI40
Mega Sage

you can try with between and operator,



find_real_file.png


if you have closed_at date you can use that one,


if not, put query as state is closed and updated as i have shown.


Hi ,


I'm facing issue when using startdate with timestamp part other than '00:00:00'.


I had tried with closed 'at or after' '2017-04-12 19:00:00' but it didn't fetch record closed at '2017-04-12 19:13:11'.


I need to check for timesatmp part , which currently i'm currently not able to do via filters on table.



Thanks,


Monica


Midhun1
Giga Guru

Hi Monica,



1)Check your timezone.


2)Else create report and add condition like "Related to" or something and try to fetch the records.