
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2018 09:51 AM
I am trying to query incidents that have a due date on today. Can someone tell me why the below code is not working, yet the comparison at the bottom returns true?
var gr1 = new GlideRecord('incident');
gr1.addQuery('due_date', 'STARTSWITH', gs.now());
while(gr1.next())
gs.print('queried incidents: ' + gr1.number) //returns nothing, but should return inc0010004 per below
var gr2 = new GlideRecord('incident');
gr2.query('number', 'INC0010004');
gr2.next();
gs.print(gr2.due_date.startsWith(gs.now())); //returns true
output:
*** Script: true
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2018 10:33 AM
sorry, left out the gr1.query(); line before while (gr1.next()).
But in any case, I would replace the STARTSWITH query with what I put above.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2018 10:04 AM
I would change it like this. Startswith is a string query, and not a reliable way to query dates.
var gr1 = new GlideRecord('incident');
gr1.addEncodedQuery('due_dateONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()');
while(gr1.next())
btw, this is the exact query I got when I queried from the incident list for all incidents where "Due date ON Today". I then right-clicked that filter and clicked Copy Query to get the query you see above.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2018 10:28 AM
Still nothing 😕
var gr1 = new GlideRecord('incident');
gr1.addEncodedQuery('due_dateONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()');
while(gr1.next())
gs.print('queried incidents: ' + gr1.number)
var gr2 = new GlideRecord('incident');
gr2.query('number', 'INC0010004');
gr2.next();
gs.print(gr2.due_date.startsWith(gs.now()));
gives me:
*** Script: true

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2018 10:33 AM
sorry, left out the gr1.query(); line before while (gr1.next()).
But in any case, I would replace the STARTSWITH query with what I put above.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2018 10:40 AM
Well that makes sense!Thanks!