- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2020 12:16 PM
Hi guys,
I have the following problem:
I´m using the method getGlideObject() to get the value of a glide date/time field in order to check if that time falls within a schedule I have created.
When using the method, It adds 5 hours to actual value of the field?
Why is this?
Is it because it is taking the time from the object with some default time zone and that´s why it adds 5 hours?
Is there a way to check the time zone in which the date is being stored?
Seems possible, but I can´t find anything related. Please help.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2020 12:44 PM
try below
var schedRec = new GlideRecord('cmn_schedule');
var name = schedRec.get('name', '8-5 weekdays');
var sched = new GlideSchedule(schedRec.sys_id);
var currentDateTime = new GlideDateTime();
currentDateTime.setValue(current.u_tsf_fecha_workshop);
gs.addErrorMessage('currentDateTime after: ' + currentDateTime.getDisplayValue());
if (sched.isInSchedule(currentDateTime)) {
var dur = new GlideDuration(60 * 60 * 16 * 1000);
var newDateTime = sched.add(currentDateTime, durToAdd, '');
// var currentWSDate = current.u_tsf_fecha_wsreal.getGlideObject();
gs.addErrorMessage('current.u_tsf_fecha_wsreal: ' + newDateTime.getDisplayValue());
} else {
current.setValue("u_tsf_fecha_workshop", "");
gs.setRedirect(current);
current.setAbortAction(true);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2020 12:19 PM
So all datetime is saved in GMT zone so it will give you that time. Can you share your script so I can help you with the script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2020 12:21 PM
Sure, Mike. This is the Script...
var schedRec = new GlideRecord('cmn_schedule');
var name = schedRec.get('name', '8-5 weekdays');
var sched = new GlideSchedule(schedRec.sys_id);
var currentDateTime = current.u_tsf_fecha_workshop.getGlideObject();
gs.addErrorMessage('currentDateTime after: ' + currentDateTime);
if (sched.isInSchedule(currentDateTime)) {
var timeToAdd = 57600; // adds 16 hrs to define the true due date
var durToAdd = new GlideDuration(timeToAdd * 1000 * 2);
var newDateTime = sched.add(currentDateTime, durToAdd);
// var currentWSDate = current.u_tsf_fecha_wsreal.getGlideObject();
// gs.addErrorMessage('current.u_tsf_fecha_wsreal.getGlideObject(): ' + currentWSDate);
} else {
current.setValue("u_tsf_fecha_workshop", "");
gs.setRedirect(current);
current.setAbortAction(true);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2020 12:27 PM
try (make sure you are getting correct value in error message)
var schedRec = new GlideRecord('cmn_schedule');
var name = schedRec.get('name', '8-5 weekdays');
var sched = new GlideSchedule(schedRec.sys_id);
var currentDateTime = new GlideDateTime();
currentDateTime.setDisplayValue(current.u_tsf_fecha_workshop);
gs.addErrorMessage('currentDateTime after: ' + currentDateTime);
if (sched.isInSchedule(currentDateTime)) {
var timeToAdd = 57600; // adds 16 hrs to define the true due date
var durToAdd = new GlideDuration(timeToAdd * 1000 * 2);
var newDateTime = sched.add(currentDateTime, durToAdd, '');
// var currentWSDate = current.u_tsf_fecha_wsreal.getGlideObject();
gs.addErrorMessage('current.u_tsf_fecha_wsreal: ' + newDateTime);
} else {
current.setValue("u_tsf_fecha_workshop", "");
gs.setRedirect(current);
current.setAbortAction(true);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2020 12:38 PM
It is adding 8 hours now so I guess it is now in a different time zone than before (5hrs)..
Do you think this snippet would work?
var tz = Packages.java.util.TimeZone.getTimeZone("America/New_York");
var time = new GlideDateTime();
time.setTZ(tz);
time.setValue(current.sysapproval.end_date);