How do I set the time zone I want a date/time variable to display on the RITM?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2018 03:03 PM
Hello!
I have a catalog item where a user will select a start date and time and an end date and time for their request. These variables are start_date and end_date. I want to leave these alone as they show up in the time the user is in.
I created two other variables MST_start_date and MST_end_date. Both of these only show up on the RITM and the Task. I want these variables to equal the start_date and end_date but in Mountain Standard Time. I still want the original start_date and end_date to appear the way they are on the RITM.
Here is the client script I have, but it is only populating the MST dates with the exact same values as the original start and end dates. Need help with the time zone conversion! Thanks in advance!
function onSubmit() {
g_form.setValue('MST_start_date', 'start_date');
g_form.setValue('MST_end_date', 'end_date');
var gDate = Packages.com.glide.glideobject.GlideDateTime(MST_start_date);
var tz = Packages.java.util.TimeZone.getTimeZone("US/Mountain");
gDate.setTZ(tz);
gDate.setDisplayValue(MST_start_date);
gDate.setDisplayValue(MST_end_date);
}
- Labels:
-
Request Management
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2018 06:27 PM
Hi,
Please see this thread for assistance: https://community.servicenow.com/community?id=community_question&sys_id=b1494725db5cdbc01dcaf3231f96...
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2018 02:25 PM
I followed along the code in that example, however I need it for a client script on a catalog item. I used info from what they did and this is what I came up with, but it is still not working
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var start = g_form.getValue('start_date');
var end = g_form.getValue('end_date');
g_form.setValue('MST_start_date', toMST(start));
g_form.setValue('MST_end_date', toMST(end));
}
function toMST(start){
var time = new GlideDateTime(start);
var tz = Packages.java.util.TimeZone.getTimeZone("US/Mountain");
time.setTZ(tz);
var timeZoneOffSet = time.getTZOffset();
time.setNumericValue(time.getNumericValue() + timeZoneOffSet);
return time;
}