How to set time zone to a date/time field in change form?

Sagar24
Tera Contributor

My requirement is to change the time zone of fields on change form (planned start date & planned enddate) based on the time zone selected. How can I achieve this? I have tried this, but I don't think there is any method client side which sets the time zone for a field. I have tried writing the onChange client script on timezone field and whenever it changes I was passing the time zone value and getting the time zone from script include but don't know how to set this to planned start date field?

 

I would appreciate it if anybody can advise or let me know if this can be done

 

Sagar24_0-1665390611996.png

 

4 REPLIES 4

Sagar Pagar
Tera Patron

Hi,

Can you share your scripts here?

 

Thanks,

Sagar Pagar

The world works with ServiceNow

H_9
Giga Guru

Hi Sagar,

Try following server side script in your logic:

gs.print(gs.nowDateTime());

var expectedTimezoneDateTime=new GlideScheduleDateTime().convertTimeZone("CET","GMT");

//You can provide a hardcoded value as well in the function GlideScheduleDateTime("02-02-2022 03:40:67");

var convertedTimeZoneDateTime= new GlideDateTime(expectedTimezoneDateTime);

gs.print(convertedTimeZoneDateTime);

 

You will have to make the server side call by glide ajax to run above code on server side and then pass the converted value back to client side.

I think this will work for you.

Please mark the answer correct if it helps. 🙂

Thanks. 🙂

Sagar24
Tera Contributor

Hello,

I would like to set the time zone of the fields so that the user can select from the calendar. This is to set the time zone for the calender and I don't want the fields to be populated with that timezone's time. Please advise if there is any way we can set this for a field without populating it

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

Is that a custom time zone field that you have created?  I am still not sure if i got your requirement can you give another example of your use case?