- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2016 02:11 AM
Dear all,
I have a custom datetime field called Scheduled Start Time in incident table, operators fill this field and, when datetime is reached, I need to update the incident state.
To implement this logic, I created a secheduled job which runs every 30 mins and performs a query where this datetime field has passed.
My problem is that the datetime "real value" stored into the custom field seems to be different from the displayed value filled by operator (e.g. displayed value is 2016-10-18 11:00:00, the real stored value is 2016-10-18 09:00:00, always 2 hours difference). This is causing an update also on incident which could not change state.
What I'm doing wrong? here's my code:
var dt = gs.nowDateTime();
var inc = new GlideRecord('incident');
//I perform a query to retrieve incidents where state is a specific value and my datetime value is reached/passed
inc.addQuery('state', 15);
inc.addQuery('u_scheduled_start_time', '<=', dt);
inc.query();
while(inc.next()) {
//I'm updating incident state to new value
inc.setValue('state', 25);
inc.update();
}
Any hint? Could I perform the same operation in a different way? Thanks in advance.
Cheers
Ernesto
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2016 02:58 AM
Solved!!!, I'm posting code just for your info:
var currentDate = gs.nowDateTime();
var dt = new GlideDateTime(currentDate);
var inc = new GlideRecord('incident');
inc.addQuery('state', 15);
inc.addQuery('u_scheduled_start_time', '<', currentDate);
inc.query();
while(inc.next()) {
//I'm retrieving the Displayed Value
var time = new GlideDateTime(inc.getDisplayValue('u_scheduled_start_time'));
//using the getNumericValue to be sure comparison won't fail in any case (maybe those 2 steps are optional)
var incDate = time.getNumericValue();
var jobDate = dt.getNumericValue();
if (incDate < jobDate) {
inc.setValue('state', 25);
inc.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2016 02:58 AM
Solved!!!, I'm posting code just for your info:
var currentDate = gs.nowDateTime();
var dt = new GlideDateTime(currentDate);
var inc = new GlideRecord('incident');
inc.addQuery('state', 15);
inc.addQuery('u_scheduled_start_time', '<', currentDate);
inc.query();
while(inc.next()) {
//I'm retrieving the Displayed Value
var time = new GlideDateTime(inc.getDisplayValue('u_scheduled_start_time'));
//using the getNumericValue to be sure comparison won't fail in any case (maybe those 2 steps are optional)
var incDate = time.getNumericValue();
var jobDate = dt.getNumericValue();
if (incDate < jobDate) {
inc.setValue('state', 25);
inc.update();
}
}