- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2020 11:31 PM
Hello Experts,
I have a custom field on the sys_user table called 'Date TZ', which is a Date/Time type.
I have a requirement where I need to show the time in this field, what ever the user chooses from the 'Time Zone' field.
For Example: if the user chooses 'Europe/London', the 'Date TZ' should show the time in 'Europe/London', as of now it shows in the default system time.
Is there a way to do this ?
Thanks
Veer
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-26-2020 11:29 PM
Hi,
I got this working with a script include and a onchange client script.
Script Include:
var DateTimeZone = Class.create();
DateTimeZone.prototype = Object.extendsObject(AbstractAjaxProcessor, {
setDateTimeZone: function() {
var timez = this.getParameter('sysparm_time_zone');
var tz = Packages.java.util.TimeZone.getTimeZone(timez);
var gr = new GlideRecord("sys_user");
gr.addActiveQuery();
gr.query();
if (gr.next()) {
var time = new GlideDateTime();
time.setTZ(tz);
var timeZoneOffset = time.getTZOffset();
time.setNumericValue(time.getNumericValue() + timeZoneOffset);
return time;
}
},
type: 'DateTimeZone'
});
Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var timezone = g_form.getValue('time_zone');
var ga = new GlideAjax('DateTimeZone');
ga.addParam('sysparm_name', 'setDateTimeZone');
ga.addParam('sysparm_time_zone', timezone);
ga.getXML(getDateTimeZone);
function getDateTimeZone(response) {
var answer = response.responseXML.documentElement.getAttribute("answer").toString();
g_form.setValue('u_date_tz', answer);
}
//Type appropriate comment here, and begin script below
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2020 11:44 PM
Hi,
You can try the following way to convert the local time to the desired timezone time:
var tz = Packages.java.util.TimeZone.getTimeZone(current.time_zone_field);
var time = new GlideDateTime();
time.setTZ(tz);
time.setValue(current.date_time_field);
Regards,
Munender
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2020 12:16 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2020 01:06 AM
Hi,
I have noticed that is the user's time zone is 'GMT', then this script gives the expected results.
But if the user's time zone is other then 'GMT' it does not give the same result.
It should give the same results for all users.
How do I achieve that ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2020 01:12 AM
Hi Veer,
I suggest you to convert whatever timezone it maybe, to UTC format and then set it, lets say for ex user timezone is PST, cpnvert to UTC and then set it according to TZ. Try this,
Hope this helps.
Regards
Omkar Mone