Date field is changing based on user profile timezone but we need to restrict that field based customized time zone field on form

Madankumar N1
Tera Contributor

Hi 
We have custom Time zone field and custom field on form. 

if different time zone user open same record date field converting automatically to based on user profile time zone how to restrict automatic date display

but is has to show always based on custom timezone field

3 REPLIES 3

asifnoor
Kilo Patron

Hi,

It is OOB functionality of Service Now to override the date based on user setting.

If you do not want an override to happen, then you need to do the conversion of the date/time into the custom Timezone that you want and show it there.

Here is sample code on how to convert to custom timezone.

var myDate = "2011-08-31 08:00:00"; //change to your dynamic value here.
var gdt = new GlideDateTime();
var tz = Packages.java.util.TimeZone.getTimeZone("IST"); //Change to your custom timezone.
gdt.setTZ(tz);
gdt.setValue(new GlideDateTime(myDate));
return gdt.getDisplayValue(); //This will return the date in your custom timezone.

Mark the comment as a correct answer and helpful if this helps.

its setting the value but correctly but when am saying the record its change the value

When you option the form again, after saving, aren't you seeing the data that it was set before?

What is the difference? is it the timezone difference or the entire date is wrong.