Query due date for todays date

Kerry10
Giga Expert

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
1 ACCEPTED SOLUTION

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.

View solution in original post

6 REPLIES 6

You are missing the object.query() also gr2 had a wrong syntax

 

var gr1 = new GlideRecord('incident');
gr1.addEncodedQuery('due_dateONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()');

gr1.query();
while(gr1.next())
gs.print('queried incidents: ' + gr1.number)

var gr2 = new GlideRecord('incident');
gr2.addQuery('number', 'INC0010004');

gr2.query()
gr2.next();
gs.print(gr2.due_date.startsWith(gs.now()));


Please mark this response as correct or helpful if it assisted you with your question.

Also you are missing brackets

 

var gr1 = new GlideRecord('incident');
gr1.addEncodedQuery('due_dateONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()');

gr1.query();
while(gr1.next())

{
gs.print('queried incidents: ' + gr1.number)

var gr2 = new GlideRecord('incident');
gr2.addQuery('number', 'INC0010004');

gr2.query()
gr2.next();
gs.print(gr2.due_date.startsWith(gs.now()));

}


Please mark this response as correct or helpful if it assisted you with your question.