Fetching records between two dates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2019 01:37 PM
Hi ,
I am trying to fetch data based on two dates but not getting any results.
Can you update me where i am doing mistake or any option to fetch data.
where alert_bin_value and alert_app_value are alert's bin and application name.
var alert_created_1=gr.sys_created_on.getDisplayValue();
var dateTime = new GlideDateTime(alert_created_1);
dateTime.addSeconds(-1800);
var modifyAlertCreatedate=dateTime;
var inc1 = new GlideRecord("incident");
inc1.addEncodedQuery("assignment_group.name="+alert_bin_value+"^u_application.name="+alert_app_value+"^stateIN1,2,3^sys_created_onONLast 2 hours@javascript:gs.beginningOfLast2Hours()@javascript:gs.endOfLast2Hours()");
inc1.addQuery('sys_created_on','>',modifyAlertCreatedate);
inc1.addQuery('sys_created_on','<',alert_created_1);
inc1.orderByDesc('sys_created_on');
inc1.query();
Please help.
- Labels:
-
Field Service Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2019 10:38 PM
Hi, I assume that the missing ' is your retyping? so var gr = new GlideRecord ('em_alert');
How does this result in a value being returned for
var alert_created_1=gr.sys_created_on.getDisplayValue();
Perhaps you should start at the beginning and work through your script line by line, ensuring you have the values expected?
All it takes is something like gs.addInfoMessage(your_variable_name); or if running\testing as background script gs.info(your_variable_name);
At the least this will give you the ability to identify where your issue is and ask some constructive questions regarding resolving it, and you might just be surprised at your own ability to resolve this yourself.
Just take it 1 small step at a time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2019 10:45 PM
Hi Tony/asifnoor,
I have already done this background check that's why I put here as didn't get anything except result is not coming.
There might be gap what I am using in addquery for data comparison. Except that everything fine.
inc1.addQuery('sys_created_on','>',modifyAlertCreatedate);
inc1.addQuery('sys_created_on','<',alert_created_1);
Are these both query correct to fetch data from incident? Not able to find any solution where is gap.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2019 11:12 PM
Hi Anil,
can you print the values of sys_created_on and modifyAlertCreatedate and alert_created_1?
Check if these 3 are in the correct date format or not.
If they are in the right format, then manually check with 1 condition at a time and see if you are getting any results or not.
Kindly post the results here as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2019 11:32 PM
I am using both modifyAlertCreatedate and alert_created_1 in User's Timezone which is IST.
would it impact the output from table?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2019 11:51 PM
If you are getting these from user's timezone, then get the sys_created_on also in user's timezone so that it is a fair comparison.
Kindly mark the comment(s) as helpful if this is helping. This would encourage community members to assist you.